diff --git a/lib/index.d.ts b/lib/index.d.ts index abf9aae..1169cb7 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -6,7 +6,10 @@ interface LightboxProps { onLoaded?: () => void; onOpened?: () => void; onCancelled?: () => void; - onError?: () => void; + onError?: (error: { + message: string; + detail: string; + }) => void; } declare const Lightbox: { (props: LightboxProps): null; @@ -35,7 +38,10 @@ declare const Lightbox: { */ interface DatatransLightboxConfig { closed?: () => void; - error?: () => void; + error?: (error: { + message: string; + detail: string; + }) => void; form?: unknown; loaded?: () => void; opened?: () => void; diff --git a/lib/index.js.map b/lib/index.js.map index dce3839..2efe8f8 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/index.ts","../src/Lightbox.tsx"],"sourcesContent":["import Lightbox from './Lightbox'\nexport type { DatatransLightboxConfig } from './Datatrans'\n\nexport default Lightbox\n","import { useEffect } from 'react'\nimport PropTypes from 'prop-types'\nimport { DatatransLightboxConfig, GlobalDatatransApi } from './Datatrans'\n\nconst getUrl = (production: boolean) => production\n ? 'https://pay.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n : 'https://pay.sandbox.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n\nexport interface LightboxProps {\n production: boolean\n transactionId: string\n onLoaded?: () => void\n onOpened?: () => void\n onCancelled?: () => void\n onError?: () => void\n}\n\ndeclare let window: Window & {\n Datatrans?: GlobalDatatransApi\n}\n\nconst startPayment = (config: DatatransLightboxConfig) => {\n if (window.Datatrans) {\n window.Datatrans.startPayment(config)\n }\n}\n\nconst cleanupLightbox = () => {\n if (window.Datatrans) {\n try {\n window.Datatrans.close()\n } catch (err) {} // eslint-disable-line no-empty\n }\n}\n\nconst Lightbox = (props: LightboxProps) => {\n useEffect(() => {\n const { production } = props\n const config =\n {\n transactionId: props.transactionId,\n loaded: props.onLoaded,\n opened: props.onOpened,\n closed: props.onCancelled,\n error: props.onError\n }\n const scriptSource = getUrl(production)\n\n if (document.querySelector('script[src=\"' + scriptSource + '\"]')) {\n startPayment(config)\n\n return cleanupLightbox\n }\n\n const script = document.createElement('script')\n script.src = scriptSource\n script.onload = () => {\n startPayment(config)\n }\n\n document.body.appendChild(script)\n\n return cleanupLightbox\n }, [])\n\n return null\n}\n\nexport default Lightbox\n\nLightbox.propTypes = {\n transactionId: PropTypes.string.isRequired,\n\n production: PropTypes.bool,\n\n onLoaded: PropTypes.func,\n onOpened: PropTypes.func,\n onCancelled: PropTypes.func,\n onError: PropTypes.func\n}\n\nLightbox.defaultProps = {\n onLoaded() {},\n onOpened() {},\n onCancelled() {},\n onError() {},\n production: false\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0B;AAC1B,wBAAsB;AAGtB,IAAM,SAAS,CAAC,eAAwB,aACpC,2EACA;AAeJ,IAAM,eAAe,CAAC,WAAoC;AACxD,MAAI,OAAO,WAAW;AACpB,WAAO,UAAU,aAAa,MAAM;AAAA,EACtC;AACF;AAEA,IAAM,kBAAkB,MAAM;AAC5B,MAAI,OAAO,WAAW;AACpB,QAAI;AACF,aAAO,UAAU,MAAM;AAAA,IACzB,SAAS,KAAP;AAAA,IAAa;AAAA,EACjB;AACF;AAEA,IAAM,WAAW,CAAC,UAAyB;AACzC,8BAAU,MAAM;AACd,UAAM,EAAE,WAAW,IAAI;AACvB,UAAM,SACJ;AAAA,MACE,eAAe,MAAM;AAAA,MACrB,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,OAAO,MAAM;AAAA,IACf;AACF,UAAM,eAAe,OAAO,UAAU;AAEtC,QAAI,SAAS,cAAc,iBAAiB,eAAe,IAAI,GAAG;AAChE,mBAAa,MAAM;AAEnB,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM;AACb,WAAO,SAAS,MAAM;AACpB,mBAAa,MAAM;AAAA,IACrB;AAEA,aAAS,KAAK,YAAY,MAAM;AAEhC,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAEA,IAAO,mBAAQ;AAEf,SAAS,YAAY;AAAA,EACnB,eAAe,kBAAAA,QAAU,OAAO;AAAA,EAEhC,YAAY,kBAAAA,QAAU;AAAA,EAEtB,UAAU,kBAAAA,QAAU;AAAA,EACpB,UAAU,kBAAAA,QAAU;AAAA,EACpB,aAAa,kBAAAA,QAAU;AAAA,EACvB,SAAS,kBAAAA,QAAU;AACrB;AAEA,SAAS,eAAe;AAAA,EACtB,WAAW;AAAA,EAAC;AAAA,EACZ,WAAW;AAAA,EAAC;AAAA,EACZ,cAAc;AAAA,EAAC;AAAA,EACf,UAAU;AAAA,EAAC;AAAA,EACX,YAAY;AACd;;;ADpFA,IAAO,cAAQ;","names":["PropTypes"]} \ No newline at end of file +{"version":3,"sources":["../src/index.ts","../src/Lightbox.tsx"],"sourcesContent":["import Lightbox from './Lightbox'\nexport type { DatatransLightboxConfig } from './Datatrans'\n\nexport default Lightbox\n","import { useEffect } from 'react'\nimport PropTypes from 'prop-types'\nimport { DatatransLightboxConfig, GlobalDatatransApi } from './Datatrans'\n\nconst getUrl = (production: boolean) => production\n ? 'https://pay.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n : 'https://pay.sandbox.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n\nexport interface LightboxProps {\n production: boolean\n transactionId: string\n onLoaded?: () => void\n onOpened?: () => void\n onCancelled?: () => void\n onError?: (error: { message: string; detail: string }) => void // eslint-disable-line no-unused-vars\n}\n\ndeclare let window: Window & {\n Datatrans?: GlobalDatatransApi\n}\n\nconst startPayment = (config: DatatransLightboxConfig) => {\n if (window.Datatrans) {\n window.Datatrans.startPayment(config)\n }\n}\n\nconst cleanupLightbox = () => {\n if (window.Datatrans) {\n try {\n window.Datatrans.close()\n } catch (err) {} // eslint-disable-line no-empty\n }\n}\n\nconst Lightbox = (props: LightboxProps) => {\n useEffect(() => {\n const { production } = props\n const config =\n {\n transactionId: props.transactionId,\n loaded: props.onLoaded,\n opened: props.onOpened,\n closed: props.onCancelled,\n error: props.onError\n }\n const scriptSource = getUrl(production)\n\n if (document.querySelector('script[src=\"' + scriptSource + '\"]')) {\n startPayment(config)\n\n return cleanupLightbox\n }\n\n const script = document.createElement('script')\n script.src = scriptSource\n script.onload = () => {\n startPayment(config)\n }\n\n document.body.appendChild(script)\n\n return cleanupLightbox\n }, [])\n\n return null\n}\n\nexport default Lightbox\n\nLightbox.propTypes = {\n transactionId: PropTypes.string.isRequired,\n\n production: PropTypes.bool,\n\n onLoaded: PropTypes.func,\n onOpened: PropTypes.func,\n onCancelled: PropTypes.func,\n onError: PropTypes.func\n}\n\nLightbox.defaultProps = {\n onLoaded() {},\n onOpened() {},\n onCancelled() {},\n onError() {},\n production: false\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0B;AAC1B,wBAAsB;AAGtB,IAAM,SAAS,CAAC,eAAwB,aACpC,2EACA;AAeJ,IAAM,eAAe,CAAC,WAAoC;AACxD,MAAI,OAAO,WAAW;AACpB,WAAO,UAAU,aAAa,MAAM;AAAA,EACtC;AACF;AAEA,IAAM,kBAAkB,MAAM;AAC5B,MAAI,OAAO,WAAW;AACpB,QAAI;AACF,aAAO,UAAU,MAAM;AAAA,IACzB,SAAS,KAAP;AAAA,IAAa;AAAA,EACjB;AACF;AAEA,IAAM,WAAW,CAAC,UAAyB;AACzC,8BAAU,MAAM;AACd,UAAM,EAAE,WAAW,IAAI;AACvB,UAAM,SACJ;AAAA,MACE,eAAe,MAAM;AAAA,MACrB,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,OAAO,MAAM;AAAA,IACf;AACF,UAAM,eAAe,OAAO,UAAU;AAEtC,QAAI,SAAS,cAAc,iBAAiB,eAAe,IAAI,GAAG;AAChE,mBAAa,MAAM;AAEnB,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM;AACb,WAAO,SAAS,MAAM;AACpB,mBAAa,MAAM;AAAA,IACrB;AAEA,aAAS,KAAK,YAAY,MAAM;AAEhC,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAEA,IAAO,mBAAQ;AAEf,SAAS,YAAY;AAAA,EACnB,eAAe,kBAAAA,QAAU,OAAO;AAAA,EAEhC,YAAY,kBAAAA,QAAU;AAAA,EAEtB,UAAU,kBAAAA,QAAU;AAAA,EACpB,UAAU,kBAAAA,QAAU;AAAA,EACpB,aAAa,kBAAAA,QAAU;AAAA,EACvB,SAAS,kBAAAA,QAAU;AACrB;AAEA,SAAS,eAAe;AAAA,EACtB,WAAW;AAAA,EAAC;AAAA,EACZ,WAAW;AAAA,EAAC;AAAA,EACZ,cAAc;AAAA,EAAC;AAAA,EACf,UAAU;AAAA,EAAC;AAAA,EACX,YAAY;AACd;;;ADpFA,IAAO,cAAQ;","names":["PropTypes"]} \ No newline at end of file diff --git a/lib/index.mjs.map b/lib/index.mjs.map index df2e315..213fa1a 100644 --- a/lib/index.mjs.map +++ b/lib/index.mjs.map @@ -1 +1 @@ -{"version":3,"sources":["../src/Lightbox.tsx","../src/index.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport PropTypes from 'prop-types'\nimport { DatatransLightboxConfig, GlobalDatatransApi } from './Datatrans'\n\nconst getUrl = (production: boolean) => production\n ? 'https://pay.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n : 'https://pay.sandbox.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n\nexport interface LightboxProps {\n production: boolean\n transactionId: string\n onLoaded?: () => void\n onOpened?: () => void\n onCancelled?: () => void\n onError?: () => void\n}\n\ndeclare let window: Window & {\n Datatrans?: GlobalDatatransApi\n}\n\nconst startPayment = (config: DatatransLightboxConfig) => {\n if (window.Datatrans) {\n window.Datatrans.startPayment(config)\n }\n}\n\nconst cleanupLightbox = () => {\n if (window.Datatrans) {\n try {\n window.Datatrans.close()\n } catch (err) {} // eslint-disable-line no-empty\n }\n}\n\nconst Lightbox = (props: LightboxProps) => {\n useEffect(() => {\n const { production } = props\n const config =\n {\n transactionId: props.transactionId,\n loaded: props.onLoaded,\n opened: props.onOpened,\n closed: props.onCancelled,\n error: props.onError\n }\n const scriptSource = getUrl(production)\n\n if (document.querySelector('script[src=\"' + scriptSource + '\"]')) {\n startPayment(config)\n\n return cleanupLightbox\n }\n\n const script = document.createElement('script')\n script.src = scriptSource\n script.onload = () => {\n startPayment(config)\n }\n\n document.body.appendChild(script)\n\n return cleanupLightbox\n }, [])\n\n return null\n}\n\nexport default Lightbox\n\nLightbox.propTypes = {\n transactionId: PropTypes.string.isRequired,\n\n production: PropTypes.bool,\n\n onLoaded: PropTypes.func,\n onOpened: PropTypes.func,\n onCancelled: PropTypes.func,\n onError: PropTypes.func\n}\n\nLightbox.defaultProps = {\n onLoaded() {},\n onOpened() {},\n onCancelled() {},\n onError() {},\n production: false\n}\n","import Lightbox from './Lightbox'\nexport type { DatatransLightboxConfig } from './Datatrans'\n\nexport default Lightbox\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,OAAO,eAAe;AAGtB,IAAM,SAAS,CAAC,eAAwB,aACpC,2EACA;AAeJ,IAAM,eAAe,CAAC,WAAoC;AACxD,MAAI,OAAO,WAAW;AACpB,WAAO,UAAU,aAAa,MAAM;AAAA,EACtC;AACF;AAEA,IAAM,kBAAkB,MAAM;AAC5B,MAAI,OAAO,WAAW;AACpB,QAAI;AACF,aAAO,UAAU,MAAM;AAAA,IACzB,SAAS,KAAP;AAAA,IAAa;AAAA,EACjB;AACF;AAEA,IAAM,WAAW,CAAC,UAAyB;AACzC,YAAU,MAAM;AACd,UAAM,EAAE,WAAW,IAAI;AACvB,UAAM,SACJ;AAAA,MACE,eAAe,MAAM;AAAA,MACrB,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,OAAO,MAAM;AAAA,IACf;AACF,UAAM,eAAe,OAAO,UAAU;AAEtC,QAAI,SAAS,cAAc,iBAAiB,eAAe,IAAI,GAAG;AAChE,mBAAa,MAAM;AAEnB,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM;AACb,WAAO,SAAS,MAAM;AACpB,mBAAa,MAAM;AAAA,IACrB;AAEA,aAAS,KAAK,YAAY,MAAM;AAEhC,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAEA,IAAO,mBAAQ;AAEf,SAAS,YAAY;AAAA,EACnB,eAAe,UAAU,OAAO;AAAA,EAEhC,YAAY,UAAU;AAAA,EAEtB,UAAU,UAAU;AAAA,EACpB,UAAU,UAAU;AAAA,EACpB,aAAa,UAAU;AAAA,EACvB,SAAS,UAAU;AACrB;AAEA,SAAS,eAAe;AAAA,EACtB,WAAW;AAAA,EAAC;AAAA,EACZ,WAAW;AAAA,EAAC;AAAA,EACZ,cAAc;AAAA,EAAC;AAAA,EACf,UAAU;AAAA,EAAC;AAAA,EACX,YAAY;AACd;;;ACpFA,IAAO,cAAQ;","names":[]} \ No newline at end of file +{"version":3,"sources":["../src/Lightbox.tsx","../src/index.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport PropTypes from 'prop-types'\nimport { DatatransLightboxConfig, GlobalDatatransApi } from './Datatrans'\n\nconst getUrl = (production: boolean) => production\n ? 'https://pay.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n : 'https://pay.sandbox.datatrans.com/upp/payment/js/datatrans-2.0.0.global.min.js'\n\nexport interface LightboxProps {\n production: boolean\n transactionId: string\n onLoaded?: () => void\n onOpened?: () => void\n onCancelled?: () => void\n onError?: (error: { message: string; detail: string }) => void // eslint-disable-line no-unused-vars\n}\n\ndeclare let window: Window & {\n Datatrans?: GlobalDatatransApi\n}\n\nconst startPayment = (config: DatatransLightboxConfig) => {\n if (window.Datatrans) {\n window.Datatrans.startPayment(config)\n }\n}\n\nconst cleanupLightbox = () => {\n if (window.Datatrans) {\n try {\n window.Datatrans.close()\n } catch (err) {} // eslint-disable-line no-empty\n }\n}\n\nconst Lightbox = (props: LightboxProps) => {\n useEffect(() => {\n const { production } = props\n const config =\n {\n transactionId: props.transactionId,\n loaded: props.onLoaded,\n opened: props.onOpened,\n closed: props.onCancelled,\n error: props.onError\n }\n const scriptSource = getUrl(production)\n\n if (document.querySelector('script[src=\"' + scriptSource + '\"]')) {\n startPayment(config)\n\n return cleanupLightbox\n }\n\n const script = document.createElement('script')\n script.src = scriptSource\n script.onload = () => {\n startPayment(config)\n }\n\n document.body.appendChild(script)\n\n return cleanupLightbox\n }, [])\n\n return null\n}\n\nexport default Lightbox\n\nLightbox.propTypes = {\n transactionId: PropTypes.string.isRequired,\n\n production: PropTypes.bool,\n\n onLoaded: PropTypes.func,\n onOpened: PropTypes.func,\n onCancelled: PropTypes.func,\n onError: PropTypes.func\n}\n\nLightbox.defaultProps = {\n onLoaded() {},\n onOpened() {},\n onCancelled() {},\n onError() {},\n production: false\n}\n","import Lightbox from './Lightbox'\nexport type { DatatransLightboxConfig } from './Datatrans'\n\nexport default Lightbox\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,OAAO,eAAe;AAGtB,IAAM,SAAS,CAAC,eAAwB,aACpC,2EACA;AAeJ,IAAM,eAAe,CAAC,WAAoC;AACxD,MAAI,OAAO,WAAW;AACpB,WAAO,UAAU,aAAa,MAAM;AAAA,EACtC;AACF;AAEA,IAAM,kBAAkB,MAAM;AAC5B,MAAI,OAAO,WAAW;AACpB,QAAI;AACF,aAAO,UAAU,MAAM;AAAA,IACzB,SAAS,KAAP;AAAA,IAAa;AAAA,EACjB;AACF;AAEA,IAAM,WAAW,CAAC,UAAyB;AACzC,YAAU,MAAM;AACd,UAAM,EAAE,WAAW,IAAI;AACvB,UAAM,SACJ;AAAA,MACE,eAAe,MAAM;AAAA,MACrB,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd,OAAO,MAAM;AAAA,IACf;AACF,UAAM,eAAe,OAAO,UAAU;AAEtC,QAAI,SAAS,cAAc,iBAAiB,eAAe,IAAI,GAAG;AAChE,mBAAa,MAAM;AAEnB,aAAO;AAAA,IACT;AAEA,UAAM,SAAS,SAAS,cAAc,QAAQ;AAC9C,WAAO,MAAM;AACb,WAAO,SAAS,MAAM;AACpB,mBAAa,MAAM;AAAA,IACrB;AAEA,aAAS,KAAK,YAAY,MAAM;AAEhC,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAEA,IAAO,mBAAQ;AAEf,SAAS,YAAY;AAAA,EACnB,eAAe,UAAU,OAAO;AAAA,EAEhC,YAAY,UAAU;AAAA,EAEtB,UAAU,UAAU;AAAA,EACpB,UAAU,UAAU;AAAA,EACpB,aAAa,UAAU;AAAA,EACvB,SAAS,UAAU;AACrB;AAEA,SAAS,eAAe;AAAA,EACtB,WAAW;AAAA,EAAC;AAAA,EACZ,WAAW;AAAA,EAAC;AAAA,EACZ,cAAc;AAAA,EAAC;AAAA,EACf,UAAU;AAAA,EAAC;AAAA,EACX,YAAY;AACd;;;ACpFA,IAAO,cAAQ;","names":[]} \ No newline at end of file diff --git a/package.json b/package.json index 7d4e965..78aaab5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-datatrans-light-box", - "version": "4.0.0", + "version": "4.0.1", "description": "Datatrans Lightbox component for React apps", "main": "lib/index.js", "module": "lib/index.mjs",