@speedlo/payments
Advanced tools
Comparing version
@@ -86,3 +86,8 @@ 'use strict'; | ||
}, [onFinish, queryPaymentStatus, redirectUrl, reportErrors]); | ||
React.useEffect(function () { | ||
var checkedForRedirect = React.useRef(false); | ||
React.useEffect(function checkPaymentRedirect() { | ||
if (checkedForRedirect.current) { | ||
return; | ||
} | ||
var _QS$parse = QS.parse(window.location.search.replace(/^\?/, '')), | ||
@@ -92,2 +97,4 @@ orderId = _QS$parse.orderId, | ||
checkedForRedirect.current = true; | ||
if (!orderId) { | ||
@@ -113,4 +120,3 @@ return; | ||
}, [handlePaymentStatus]); | ||
var executeGoPayPayment = function executeGoPayPayment(gatewayUrl) { | ||
var executeGoPayPayment = React.useCallback(function (gatewayUrl) { | ||
try { | ||
@@ -150,4 +156,3 @@ setPaymentLoading(true); | ||
} | ||
}; | ||
}, [handlePaymentStatus]); | ||
return { | ||
@@ -154,0 +159,0 @@ executeGoPayPayment: executeGoPayPayment, |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=e(require("qs-lite")),t=e(require("react")),n=e(require("scriptjs"));"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var o=function(){return null};exports.useGoPay=function(e,i){var u=void 0===i?{}:i,a=u.onError,c=void 0===a?o:a,s=u.onFinish,l=void 0===s?o:s,f=u.redirectUrl,y=t.useState(!1),d=y[0],m=y[1],b=t.useCallback(function(e){return e?!e.isSuccess&&(c(e.userErrors),!0):(c([]),!0)},[c]),h=t.useCallback(function(r,t){try{return Promise.resolve(e(r,t)).then(function(e){b(e)||(l(),f&&location.replace(f))})}catch(e){return Promise.reject(e)}},[l,e,f,b]);return t.useEffect(function(){var e=r.parse(window.location.search.replace(/^\?/,"")),t=e.orderId,n=e.userToken;if(t){var o,i=setTimeout(function(){return m(!0)},500);try{o=window.atob(n)}catch(e){throw new Error("User token decoding failed in useGoPay: "+e)}h(t,o).finally(function(){clearTimeout(i),m(!1)})}},[h]),{executeGoPayPayment:function(e){try{m(!0);var r=function(r,t){try{var o=(i=e.includes("gw.sandbox.gopay.com")?"https://gw.sandbox.gopay.com/gp-gw/js/embed.js":"https://gate.gopay.cz/gp-gw/js/embed.js",Promise.resolve(new Promise(function(e){n(i,e)})).then(function(){var r={gatewayUrl:e,inline:!0};return Promise.resolve(new Promise(function(e){_gopay.checkout(r,function(r){e(r.id)})})).then(function(){return Promise.resolve(h()).then(function(){})})}))}catch(e){return t(!0,e)}var i;return o&&o.then?o.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)}(0,function(e,r){if(m(!1),e)throw r;return r});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},paymentLoading:d}}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=e(require("qs-lite")),t=e(require("react")),n=e(require("scriptjs"));"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var o=function(){return null};exports.useGoPay=function(e,i){var u=void 0===i?{}:i,c=u.onError,a=void 0===c?o:c,s=u.onFinish,l=void 0===s?o:s,f=u.redirectUrl,y=t.useState(!1),d=y[0],m=y[1],b=t.useCallback(function(e){return e?!e.isSuccess&&(a(e.userErrors),!0):(a([]),!0)},[a]),h=t.useCallback(function(r,t){try{return Promise.resolve(e(r,t)).then(function(e){b(e)||(l(),f&&location.replace(f))})}catch(e){return Promise.reject(e)}},[l,e,f,b]),v=t.useRef(!1);return t.useEffect(function(){if(!v.current){var e=r.parse(window.location.search.replace(/^\?/,"")),t=e.orderId,n=e.userToken;if(v.current=!0,t){var o,i=setTimeout(function(){return m(!0)},500);try{o=window.atob(n)}catch(e){throw new Error("User token decoding failed in useGoPay: "+e)}h(t,o).finally(function(){clearTimeout(i),m(!1)})}}},[h]),{executeGoPayPayment:t.useCallback(function(e){try{m(!0);var r=function(r,t){try{var o=(i=e.includes("gw.sandbox.gopay.com")?"https://gw.sandbox.gopay.com/gp-gw/js/embed.js":"https://gate.gopay.cz/gp-gw/js/embed.js",Promise.resolve(new Promise(function(e){n(i,e)})).then(function(){var r={gatewayUrl:e,inline:!0};return Promise.resolve(new Promise(function(e){_gopay.checkout(r,function(r){e(r.id)})})).then(function(){return Promise.resolve(h()).then(function(){})})}))}catch(e){return t(!0,e)}var i;return o&&o.then?o.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)}(0,function(e,r){if(m(!1),e)throw r;return r});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[h]),paymentLoading:d}}; | ||
//# sourceMappingURL=payments.cjs.production.min.js.map |
@@ -82,3 +82,8 @@ import QS from 'qs-lite'; | ||
}, [onFinish, queryPaymentStatus, redirectUrl, reportErrors]); | ||
React.useEffect(function () { | ||
var checkedForRedirect = React.useRef(false); | ||
React.useEffect(function checkPaymentRedirect() { | ||
if (checkedForRedirect.current) { | ||
return; | ||
} | ||
var _QS$parse = QS.parse(window.location.search.replace(/^\?/, '')), | ||
@@ -88,2 +93,4 @@ orderId = _QS$parse.orderId, | ||
checkedForRedirect.current = true; | ||
if (!orderId) { | ||
@@ -109,4 +116,3 @@ return; | ||
}, [handlePaymentStatus]); | ||
var executeGoPayPayment = function executeGoPayPayment(gatewayUrl) { | ||
var executeGoPayPayment = React.useCallback(function (gatewayUrl) { | ||
try { | ||
@@ -146,4 +152,3 @@ setPaymentLoading(true); | ||
} | ||
}; | ||
}, [handlePaymentStatus]); | ||
return { | ||
@@ -150,0 +155,0 @@ executeGoPayPayment: executeGoPayPayment, |
{ | ||
"name": "@speedlo/payments", | ||
"version": "1.2.8", | ||
"version": "1.2.9", | ||
"scripts": { | ||
@@ -30,3 +30,3 @@ "build": "tsdx build --tsconfig ./tsconfig.build.json", | ||
}, | ||
"gitHead": "b5cde6dd26aad14a35bea114d865f261e4000a21" | ||
"gitHead": "9c6adaffc56e6bbecf4b70d77e5f65c0ce542afe" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
101662
2.09%302
3.78%