gainfedpay
Version:
``` import GainFedPay from "@ledgergreen/gainfedpay"
83 lines (72 loc) • 2.88 kB
JavaScript
function $parcel$defineInteropFlag(a) {
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$defineInteropFlag(module.exports);
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
const $be6f0e84320366a7$export$ca6dda5263526f75 = "https://sdk-test.gainfedpay.com";
class $74b5a09bc6caf920$var$GainFedPay {
constructor(api_token){
this.token = api_token;
}
async pay({ amount: amount, orderId: orderId }, { onSuccess: onSuccess, onFailure: onFailure }) {
if (!orderId || orderId === "" || orderId === undefined) {
console.error("Order Id required");
return;
}
if (!amount || amount <= 0) {
console.error("Amount must be an positive integer");
return;
}
const resp = await fetch((0, $be6f0e84320366a7$export$ca6dda5263526f75) + "/api/checkout", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + this.token
},
body: JSON.stringify({
amount: amount,
orderId: orderId
})
});
const data = await resp.json();
if (data.error) {
console.log(data.error);
return;
}
await $74b5a09bc6caf920$var$openModal(data.token);
window.onmessage = async function(e) {
e.preventDefault();
const data = JSON.parse(e.data);
if (data.paymentStatus === "success") onSuccess({
transactionID: data.transactionID,
orderID: data.orderID
});
if (data.paymentStatus === "failed") onFailure(data);
};
}
}
async function $74b5a09bc6caf920$var$openModal(token) {
const div = document.createElement("div");
div.style.position = "fixed";
div.style.top = 0;
div.style.left = 0;
div.style.right = 0;
div.style.bottom = 0;
div.style.background = "#F9F9F97B";
const div2 = document.createElement("div");
div2.setAttribute("id", "gain-feed-checkout-frame");
div2.style.position = "absolute";
div2.style.top = 0;
div2.style.left = 0;
div2.style.width = "100%";
div2.style.height = "100%";
div2.innerHTML = `<iframe src='${0, $be6f0e84320366a7$export$ca6dda5263526f75}/checkout?token=${token}' style='width:100%;height:100%;border:none'/>`;
div.append(div2);
document.body.append(div);
}
var $74b5a09bc6caf920$export$2e2bcd8739ae039 = $74b5a09bc6caf920$var$GainFedPay;
var $4fa36e821943b400$export$2e2bcd8739ae039 = (0, $74b5a09bc6caf920$export$2e2bcd8739ae039);
//# sourceMappingURL=index.js.map