react-payline
Version:
_This is an unofficial repository_
78 lines • 4.27 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var usePayline_1 = require("./usePayline");
;
exports.PaylineWidget = function (_a) {
var token = _a.token, _b = _a.template, template = _b === void 0 ? 'column' : _b, _c = _a.embeddedRedirectionAllowed, embeddedRedirectionAllowed = _c === void 0 ? false : _c, partnerReturnUrl = _a.partnerReturnUrl, onWillInit = _a.onWillInit, onWillShow = _a.onWillShow, onFinalStateHasBeenReached = _a.onFinalStateHasBeenReached, onDidShowState = _a.onDidShowState, onWillDisplayMessage = _a.onWillDisplayMessage, onWillRemoveMessage = _a.onWillRemoveMessage, onBeforePayment = _a.onBeforePayment, htmlAttributes = __rest(_a, ["token", "template", "embeddedRedirectionAllowed", "partnerReturnUrl", "onWillInit", "onWillShow", "onFinalStateHasBeenReached", "onDidShowState", "onWillDisplayMessage", "onWillRemoveMessage", "onBeforePayment"]);
var eventHandlers = {
onWillInit: onWillInit,
onWillShow: onWillShow,
onFinalStateHasBeenReached: onFinalStateHasBeenReached,
onDidShowState: onDidShowState,
onWillDisplayMessage: onWillDisplayMessage,
onWillRemoveMessage: onWillRemoveMessage,
onBeforePayment: onBeforePayment,
};
var eventHandlersRef = react_1.useRef(eventHandlers);
eventHandlersRef.current = eventHandlers;
react_1.useEffect(function () {
var propNames = Object.keys(eventHandlersRef.current);
propNames.forEach(function (propName) {
window["Payline_" + propName] = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var eventHandler = eventHandlersRef.current[propName];
if (eventHandler) {
return eventHandler.apply(void 0, args);
}
return true;
};
});
return function () {
propNames.forEach(function (propName) {
delete window["Payline_" + propName];
});
};
}, []);
var payline = usePayline_1.usePaylineApi();
react_1.useEffect(function () {
if (payline) {
payline.reset();
return function () { return payline.hide(); };
}
}, [payline]);
return (react_1.default.createElement("div", __assign({ "data-token": token, "data-template": template, "data-embeddedredirectionallowed": embeddedRedirectionAllowed, "data-partnerreturnurl": partnerReturnUrl, "data-event-willinit": "Payline_onWillInit", "data-event-willshow": "Payline_onWillShow", "data-event-finalstatehasbeenreached": "Payline_onFinalStateHasBeenReached", "data-event-didshowstate": "Payline_onDidShowState", "data-event-willdisplaymessage": "Payline_onWillDisplayMessage", "data-event-willremovemessage": "Payline_onWillRemoveMessage", "data-event-beforepayment": "Payline_onBeforePayment" }, htmlAttributes, { id: "PaylineWidget" })));
};
//# sourceMappingURL=PaylineWidget.js.map