paytm-blink-checkout-react
Version:
React based implementation for Paytm Blink Checkout JS
1 lines • 12.7 kB
JavaScript
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(t,e){t.exports=require("react")},function(t,e,n){"use strict";n.r(e),n.d(e,"CheckoutProvider",(function(){return S})),n.d(e,"Checkout",(function(){return F})),n.d(e,"injectCheckout",(function(){return L}));var r=n(0),o=n.n(r),c={PROJECT_NAME:"Paytm Blink Checkout JS",ENV:{PROD:"PROD",STAGE:"STAGE"},HOSTS:{PROD:"https://securegw.paytm.in",STAGE:"https://securegw-stage.paytm.in"},LINKS:{CHECKOUT_JS_URL:"/merchantpgpui/checkoutjs/merchants/"},ERRORS:{INIT:"An error during initialization!",INVOKE:"An error during invoking!",MERCHANT_ID_NOT_FOUND:"Please provide merchant id!",CHECKOUT_NOT_AVAILABLE:"Checkout JS library not found. Please make sure you have included checkout js!",INVALID_CHECKOUT_JS_INSTANCE:"Invalid instance provided!",FAILED_TO_LOAD_SCRIPT:"Failed to load script!"},IDS:{CHECKOUT_ELEMENT:"paytm-checkout-wrapper-"}};Object.keys(c.ERRORS).forEach((function(t){c.ERRORS[t]="".concat(c.PROJECT_NAME,": ").concat(c.ERRORS[t])}));var i=c;function u(t){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function a(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function f(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?a(Object(n),!0).forEach((function(e){O(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function p(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function l(t,e){return(l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function y(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=d(t);if(e){var o=d(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return b(this,n)}}function b(t,e){if(e&&("object"===u(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return h(t)}function h(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(t){return(d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function O(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var v=o.a.createContext(null);function m(t){return"boolean"==typeof t?t:"string"==typeof t&&"true"===t}var S=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&l(t,e)}(u,t);var e,n,r,c=y(u);function u(){var t;p(this,u);for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return O(h(t=c.call.apply(c,[this].concat(n))),"elementId",i.IDS.CHECKOUT_ELEMENT+(new Date).getTime()),O(h(t),"isScriptLoaded",!1),O(h(t),"isScriptLoading",!1),O(h(t),"config",null),O(h(t),"state",{checkoutJsInstance:null}),O(h(t),"setupCheckoutJsOnScriptLoad",(function(){var e=t.getCheckoutJsObj();t.isScriptLoading=!0,t.isScriptLoaded=!1,e&&e.onLoad?e.onLoad((function(){t.isScriptLoading=!1,t.isScriptLoaded=!0,t.initializeCheckout()})):console.error(i.ERRORS.INVALID_CHECKOUT_JS_INSTANCE)})),O(h(t),"initializeCheckout",(function(){var e=t.props.openInPopup,n=void 0===e||e,r=f({},t.getCheckoutJsObj());r&&r.init&&r.invoke?r.init(f(f({},t.props.config),{},{root:m(n)?"":"#".concat(t.elementId)})).then((function(e){t.setState({checkoutJsInstance:r})})).catch((function(t){console.error(i.ERRORS.INIT,t)})):console.error(i.ERRORS.INVALID_CHECKOUT_JS_INSTANCE)})),t}return e=u,(n=[{key:"componentDidMount",value:function(){this.preSetup()}},{key:"componentDidUpdate",value:function(t){var e=this;["config","checkoutJsInstance","openInPopup","env"].some((function(n){return t[n]!==e.props[n]}))&&this.preSetup()}},{key:"preSetup",value:function(){var t=this.props,e=t.config,n=t.checkoutJsInstance,r=e&&e.merchant&&e.merchant.mid;if(r){var o=this.config&&this.config.merchant&&this.config.merchant.mid;this.config=e,(n||this.isScriptLoaded)&&o===r?this.initializeCheckout():(!this.isScriptLoading||o&&r!==o)&&this.loadCheckoutScript(r)}else console.error(i.ERRORS.MERCHANT_ID_NOT_FOUND)}},{key:"loadCheckoutScript",value:function(t){var e=this,n=i.ENV[(this.props.env||"").toUpperCase()]||i.ENV.PROD,r=document.createElement("script");r.async=!0,r.src=i.HOSTS[n]+i.LINKS.CHECKOUT_JS_URL.concat(t),r.type="application/javascript",r.onload=this.setupCheckoutJsOnScriptLoad,r.onerror=function(t){console.error(i.ERRORS.FAILED_TO_LOAD_SCRIPT,t),e.isScriptLoading=!1},document.body.appendChild(r),this.isScriptLoading=!0}},{key:"getCheckoutJsObj",value:function(){return this.props.checkoutJsInstance?this.props.checkoutJsInstance:window&&window.Paytm&&window.Paytm.CheckoutJS?window.Paytm.CheckoutJS:(console.warn(i.ERRORS.CHECKOUT_NOT_AVAILABLE),null)}},{key:"render",value:function(){var t=this.state.checkoutJsInstance;return o.a.createElement(v.Provider,{value:{checkoutJsInstance:t,elementId:this.elementId}},this.props.children)}}])&&s(e.prototype,n),r&&s(e,r),Object.defineProperty(e,"prototype",{writable:!1}),u}(r.Component);function j(t){return(j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function E(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function P(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?E(Object(n),!0).forEach((function(e){g(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):E(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function g(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function w(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function R(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function _(t,e,n){return e&&R(t.prototype,e),n&&R(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function k(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&C(t,e)}function C(t,e){return(C=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function I(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=D(t);if(e){var o=D(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return T(this,n)}}function T(t,e){if(e&&("object"===j(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function D(t){return(D=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var L=function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return function(n){k(c,n);var r=I(c);function c(){return w(this,c),r.apply(this,arguments)}return _(c,[{key:"render",value:function(){var n=this;return o.a.createElement(v.Consumer,null,(function(r){var c=e?r:{checkoutJsInstance:r&&r.checkoutJsInstance};return o.a.createElement(t,P(P({},n.props),c))}))}}]),c}(r.Component)};function J(t){return(J="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function N(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function A(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function U(t,e){return(U=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function x(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=M(t);if(e){var o=M(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return H(this,n)}}function H(t,e){if(e&&("object"===J(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return K(t)}function K(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function M(t){return(M=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function V(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var B=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&U(t,e)}(u,t);var e,n,r,c=x(u);function u(){var t;N(this,u);for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return V(K(t=c.call.apply(c,[this].concat(n))),"checkoutJsInstance",null),V(K(t),"state",{elementId:""}),t}return e=u,(n=[{key:"componentDidMount",value:function(){this.setState({elementId:this.props.elementId})}},{key:"componentDidUpdate",value:function(){var t=this.checkoutJsInstance,e=this.props.checkoutJsInstance;e&&t!==e&&this.invoke(e)}},{key:"invoke",value:function(t){if(this.checkoutJsInstance=t,t&&t.invoke)try{t.invoke()}catch(t){console.error(i.ERRORS.INVOKE,t)}}},{key:"render",value:function(){return o.a.createElement("div",{id:this.state.elementId})}}])&&A(e.prototype,n),r&&A(e,r),Object.defineProperty(e,"prototype",{writable:!1}),u}(r.Component),F=L(B)}]);