UNPKG

react-shockinflux-payview

Version:
147 lines (124 loc) 5.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require("react"); var _react2 = _interopRequireDefault(_react); var _propTypes = require("prop-types"); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var shockinfluxPayview = function (_Component) { _inherits(shockinfluxPayview, _Component); function shockinfluxPayview(props) { _classCallCheck(this, shockinfluxPayview); var _this = _possibleConstructorReturn(this, (shockinfluxPayview.__proto__ || Object.getPrototypeOf(shockinfluxPayview)).call(this, props)); _this.payWithShockinflux = _this.payWithShockinflux.bind(_this); _this.loadScript = _this.loadScript.bind(_this); _this.state = { scriptLoaded: null, text: _this.props.text || "Make Payment", currency: _this.props.currency || "ngn", template: _this.props.template || "modern", language: _this.props.language || "en", action: _this.props.action || "float", country: _this.props.country || "ng" }; return _this; } _createClass(shockinfluxPayview, [{ key: "componentDidMount", value: function componentDidMount() { var _this2 = this; this.setState({ scriptLoaded: new Promise(function (resolve) { _this2.loadScript(function () { resolve(); }); }) }); } }, { key: "loadScript", value: function loadScript(callback) { var script = document.createElement("script"); script.src = 'https://scripts-cdn.boxedall.com/shockinflux/v2/payview/js/shockpaymentv2_client.js'; document.getElementsByTagName("head")[0].appendChild(script); if (script.readyState) { // IE script.onreadystatechange = function () { if (script.readyState === "loaded" || script.readyState === "complete") { script.onreadystatechange = null; callback(); } }; } else { // Others script.onload = function () { callback(); }; } } }, { key: "payWithShockinflux", value: function payWithShockinflux() { var _this3 = this; this.state.scriptLoaded && this.state.scriptLoaded.then(function () { window.shock_payview({ email: _this3.props.email, amount: _this3.props.amount, currency: _this3.state.currency, template: _this3.state.template, language: _this3.state.language, action: _this3.state.action, transactionid: _this3.props.transactionid, storeid: _this3.props.storeid, comment: _this3.props.currency, onclose: function onclose() { return _this3.props.close(); }, callback: function callback(response) { return _this3.props.callback(response); } }); }); } }, { key: "render", value: function render() { var CustomTag = "" + this.props.tag; return _react2.default.createElement( _react.Fragment, null, _react2.default.createElement( CustomTag, { className: this.state.class, onClick: this.payWithShockinflux }, this.state.text ) ); } }]); return shockinfluxPayview; }(_react.Component); shockinfluxPayview.defaultProps = { tag: "button" }; shockinfluxPayview.propTypes = { email: _propTypes2.default.string.isRequired, amount: _propTypes2.default.number.isRequired, currency: _propTypes2.default.string, template: _propTypes2.default.string, language: _propTypes2.default.string, action: _propTypes2.default.string, transactionid: _propTypes2.default.string.isRequired, storeid: _propTypes2.default.string.isRequired, comment: _propTypes2.default.string, country: _propTypes2.default.string, callback: _propTypes2.default.func.isRequired, close: _propTypes2.default.func.isRequired }; exports.default = shockinfluxPayview; //# sourceMappingURL=shockinflux.min.js.map