airwallex-payment-elements 0.2.40 → 0.2.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/bin/airwallex.cjs.js +2 -3
  2. package/lib/bin/airwallex.cjs.js.map +1 -1
  3. package/lib/bin/airwallex.es.js +2 -3
  4. package/lib/bin/airwallex.es.js.map +1 -1
  5. package/lib/bin/airwallex.iife.js +2 -3
  6. package/lib/bin/airwallex.iife.js.map +1 -1
  7. package/lib/bin/index.d.ts +28 -4
  8. package/lib/bin/{npmPackage/index.test.d.ts → index.test.d.ts} +0 -0
  9. package/package.json +1 -1
  10. package/types/airwallex.d.ts +3 -2
  11. package/types/element.d.ts +14 -5
  12. package/types/fraud.d.ts +3 -0
  13. package/types/index.d.ts +2 -0
  14. package/types/redirectElement.d.ts +6 -4
  15. package/lib/bin/airwallex.d.ts +0 -39
  16. package/lib/bin/airwallex.test.d.ts +0 -1
  17. package/lib/bin/card.d.ts +0 -31
  18. package/lib/bin/card.test.d.ts +0 -1
  19. package/lib/bin/cardNumber.d.ts +0 -38
  20. package/lib/bin/cardNumber.test.d.ts +0 -1
  21. package/lib/bin/cvc.d.ts +0 -18
  22. package/lib/bin/cvc.test.d.ts +0 -1
  23. package/lib/bin/dropIn.d.ts +0 -9
  24. package/lib/bin/dropIn.test.d.ts +0 -1
  25. package/lib/bin/element.d.ts +0 -20
  26. package/lib/bin/element.test.d.ts +0 -1
  27. package/lib/bin/expiry.d.ts +0 -5
  28. package/lib/bin/expiry.test.d.ts +0 -1
  29. package/lib/bin/fraud.d.ts +0 -8
  30. package/lib/bin/fraud.test.d.ts +0 -1
  31. package/lib/bin/fullFeaturedCard.d.ts +0 -10
  32. package/lib/bin/fullFeaturedCard.test.d.ts +0 -1
  33. package/lib/bin/handle3dsFlow.d.ts +0 -31
  34. package/lib/bin/handle3dsFlow.test.d.ts +0 -1
  35. package/lib/bin/npmPackage/index.d.ts +0 -24
  36. package/lib/bin/paymentRequestButton.d.ts +0 -9
  37. package/lib/bin/paymentRequestButton.test.d.ts +0 -1
  38. package/lib/bin/processParams.d.ts +0 -4
  39. package/lib/bin/processParams.test.d.ts +0 -1
  40. package/lib/bin/qrcode.d.ts +0 -9
  41. package/lib/bin/qrcode.test.d.ts +0 -1
  42. package/lib/bin/redirect.d.ts +0 -7
  43. package/lib/bin/redirect.test.d.ts +0 -1
  44. package/lib/bin/threeDsChallenge.d.ts +0 -12
  45. package/lib/bin/threeDsChallenge.test.d.ts +0 -1
  46. package/lib/bin/threeDsFrictionless.d.ts +0 -10
  47. package/lib/bin/threeDsFrictionless.test.d.ts +0 -1
  48. package/lib/bin/util.d.ts +0 -22
  49. package/lib/bin/util.test.d.ts +0 -1
  50. package/lib/bin/wechat.d.ts +0 -9
  51. package/lib/bin/wechat.test.d.ts +0 -1
@@ -1,4 +1,3 @@
1
- /* Airwallex Checkout Component Version [0.2.40] */
2
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},t={prod:"https://pci-api.airwallex.com",demo:"https://pci-api-demo.airwallex.com",staging:"https://pci-api-staging.airwallex.com",qa:"https://pci-api-qa.airwallex.com",preview:"https://pci-api-preview.airwallex.com",dev:"http://localhost:8080"};class n{constructor(e,t){var n,i;this.domElement=null,this.gatewayUrl=e,this.options=t,this.iframe=window.document.createElement("iframe"),this.iframe.setAttribute("frameborder","0"),this.iframe.setAttribute("allowtransparency","true"),this.iframe.setAttribute("importance","high"),this.iframe.setAttribute("scrolling","no"),this.iframe.setAttribute("allowpaymentrequest","true"),null===(n=this.iframe)||void 0===n||n.setAttribute("style","\n height: 0;\n width: 100%;\n display: block;\n "),i=e=>{var t,n,i;if(e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)){const t=new CustomEvent(null===(n=e.data)||void 0===n?void 0:n.code,{detail:{type:null===(i=e.data)||void 0===i?void 0:i.type},bubbles:!0,composed:!0});window.document.dispatchEvent(t)}},window.addEventListener("message",(e=>{window.ReactNativeWebView&&window.ReactNativeWebView.postMessage(JSON.stringify(e.data)),i(e)}))}addResizeListener(e){window.addEventListener("message",(t=>{var n,i,o,l;if(t.origin===this.gatewayUrl&&t.isTrusted&&"onResize"===(null===(n=t.data)||void 0===n?void 0:n.code)&&e===(null===(i=t.data)||void 0===i?void 0:i.type)){const e=null===(o=this.iframe)||void 0===o?void 0:o.style;e&&(e.height=`${null===(l=t.data)||void 0===l?void 0:l.height}px`)}}))}mount(e){if("string"!=typeof e)return(null==e?void 0:e.hasChildNodes())&&(e.innerHTML=""),this.iframe&&e.appendChild(this.iframe),this.domElement=e,e;{const t=window.document.getElementById(e);return(null==t?void 0:t.hasChildNodes())&&(t.innerHTML=""),this.iframe&&(null==t||t.appendChild(this.iframe)),t&&(this.domElement=t),t}}blur(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"blur"},this.gatewayUrl)}clear(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"clear"},this.gatewayUrl)}destroy(){var e;this.clear(),null===(e=this.iframe)||void 0===e||e.remove(),this.iframe=null}focus(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"focus"},this.gatewayUrl)}unmount(){var e;this.clear(),this.iframe&&(null===(e=this.domElement)||void 0===e||e.removeChild(this.iframe))}update(e){var t,n;this.options={...this.options,...e},null===(n=null===(t=this.iframe)||void 0===t?void 0:t.contentWindow)||void 0===n||n.postMessage({code:"update",options:e},this.gatewayUrl)}async confirm(){throw new Error("Confirm is not supported in ElementBase")}success(e){throw new Error(`Call success with ${e.id} is not supported in ElementBase`)}fail(e){throw new Error(`Call fail with ${e.code}: ${e.message} is not supported in ElementBase`)}}const i=["cardNumber","expiry","cvc","paymentRequestButton","card","wechat","qrcode","redirect","dropIn","fullFeaturedCard","threeDsFrictionless","threeDsChallenge"],o={},l={cardNumber:null,expiry:null,cvc:null,threeDsFrictionless:null,threeDsChallenge:null,paymentRequestButton:null,card:null,wechat:null,qrcode:null,redirect:null,dropIn:null,fullFeaturedCard:null},r=e=>{var t;return i.includes(e)?(null===(t=l[e])||void 0===t||t.destroy(),l[e]=null,!0):(console.warn(`destroyElement with type: ${e} not support!`),!1)},a=e=>i.includes(e)?l[e]:(console.warn(`getElement with type: ${e} not support!`),null),s=(e,t)=>i.includes(e)?(l[e]=t,!0):(console.warn(`destroyElement with type: ${e} not support!`),!1);class d extends n{constructor(e,t,n){var i,l,r,a;super(e,n),this.confirmResponse=t,null===(i=this.iframe)||void 0===i||i.setAttribute("src",`${e}/#/elements/3ds-frictionless?options=${encodeURIComponent(JSON.stringify(this.options))}&lang=${null===(l=o)||void 0===l?void 0:l.locale}`),null===(r=this.iframe)||void 0===r||r.setAttribute("name","Airwallex 3DS frictionless iframe"),null===(a=this.iframe)||void 0===a||a.setAttribute("title","Airwallex 3DS frictionless iframe"),window.addEventListener("message",(e=>{var t,n,i,o;e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)&&"threeDsFrictionless"===(null===(n=e.data)||void 0===n?void 0:n.type)&&(null===(o=null===(i=this.iframe)||void 0===i?void 0:i.contentWindow)||void 0===o||o.postMessage({code:"update",data:this.confirmResponse},this.gatewayUrl))}))}async confirm(){var e,t;return null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"confirm",data:this.confirmResponse},this.gatewayUrl),null}}class c extends n{constructor(e,t,n){var i,o,l,r,a,s,d,c,u;super(e,n),this.confirmResponse=t;const w=(null==n?void 0:n.customizeChallengeWindowSize)&&b[null==n?void 0:n.customizeChallengeWindowSize]?b[null==n?void 0:n.customizeChallengeWindowSize]:b["05"],h=(null===(i=null==n?void 0:n.style)||void 0===i?void 0:i.popupWidth)?`${null===(o=null==n?void 0:n.style)||void 0===o?void 0:o.popupWidth}px`:w[0],p=(null===(l=null==n?void 0:n.style)||void 0===l?void 0:l.popupHeight)?`${null===(r=null==n?void 0:n.style)||void 0===r?void 0:r.popupHeight}px`:w[1];null===(a=this.iframe)||void 0===a||a.setAttribute("src",`${e}/#/elements/3ds-challenge?options=${encodeURIComponent(JSON.stringify(this.options))}`),null===(s=this.iframe)||void 0===s||s.setAttribute("name","Airwallex 3DS challenge iframe"),null===(d=this.iframe)||void 0===d||d.setAttribute("title","Airwallex 3DS challenge iframe"),null===(c=this.iframe)||void 0===c||c.setAttribute("scrolling","yes"),null===(u=this.iframe)||void 0===u||u.setAttribute("style",`\n background: #fff;\n width: ${h};\n height: ${p};\n position: ${(null==n?void 0:n.useDefaultStyle)?"absolute":"relative"};\n top: ${(null==n?void 0:n.useDefaultStyle)?"50%":"0"};\n left: ${(null==n?void 0:n.useDefaultStyle)?"50%":"0"};\n transform: ${(null==n?void 0:n.useDefaultStyle)?"translate(-50%, -50%)":"none"};\n border-radius: ${(null==n?void 0:n.useDefaultStyle)?"4px":"0"};\n `),window.addEventListener("message",(e=>{var t,n,i,o;e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)&&"threeDsChallenge"===(null===(n=e.data)||void 0===n?void 0:n.type)&&(null===(o=null===(i=this.iframe)||void 0===i?void 0:i.contentWindow)||void 0===o||o.postMessage({code:"update",data:this.confirmResponse},this.gatewayUrl))}))}async confirm(){var e,t;return null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"confirm",data:this.confirmResponse},this.gatewayUrl),null}}let u,w,h,p,m,v;const g={resolver:null,reject:null,awaiting:!1},f=e=>{var t;null===(t=document.querySelector(`#${e}`))||void 0===t||t.remove(),r("threeDsFrictionless"===e?"threeDsFrictionless":"threeDsChallenge")},y=()=>{g.awaiting=!1,g.resolver=null,g.reject=null},x=e=>{var t,n,i;const o="data"in e?e.data:e.detail,l=["hpp","api"].includes(h),r=l?null:a(h),d=(null==r?void 0:r.gatewayUrl)||window.location.origin;("data"in e&&e.origin===d&&e.isTrusted||l)&&"threeDsFrictionless"===(null==o?void 0:o.type)&&(f("threeDsChallenge"),"onSuccess"===(null==o?void 0:o.code)&&(console.log("frictionlessHandler onSuccess",(new Date).toLocaleTimeString()),null===(t=g.resolver)||void 0===t||t.call(g,o),y(),f("threeDsFrictionless")),["onError","onChallengeError"].includes(null==o?void 0:o.code)&&(console.log(`frictionlessHandler ${null==o?void 0:o.code}`,(new Date).toLocaleTimeString()),null===(n=g.reject)||void 0===n||n.call(g,o),y(),f("threeDsFrictionless")),"onChallenge"===(null==o?void 0:o.code)&&(console.log("frictionlessHandler onChallenge threeDsFrictionlessType",(new Date).toLocaleTimeString()),f("threeDsFrictionless"),w?u=w:(u=document.createElement("div"),u.setAttribute("id","threeDsChallenge"),u.setAttribute("style","\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 0;\n z-index: 1500;\n overflow: hidden;\n background: rgba(0, 0, 0, 0.75);\n "),document.body.appendChild(u)),s("threeDsChallenge",new c(m,o,{origin:window.location.origin,style:{popupWidth:undefined,popupHeight:undefined},useDefaultStyle:null===w,customizeChallengeWindowSize:p,intent:v})),window.addEventListener("message",A),null===(i=a("threeDsChallenge"))||void 0===i||i.mount(u)))},A=e=>{var t,n;const i="data"in e?e.data:e.detail,o=["hpp","api"].includes(h),l=o?null:a(h),r=(null==l?void 0:l.gatewayUrl)||window.location.origin;("data"in e&&e.origin===r&&e.isTrusted||o)&&"threeDsChallenge"===(null==i?void 0:i.type)&&("onReady"===(null==i?void 0:i.code)&&(console.log("challengeHandler onReady",(new Date).toLocaleTimeString()),setTimeout((()=>{u.style.height="100%"}),2e3)),"onChallengeSuccess"===(null==i?void 0:i.code)&&(u.style.height="0"),"onSuccess"===(null==i?void 0:i.code)&&(console.log("challengeHandler onSuccess",(new Date).toLocaleTimeString()),null===(t=g.resolver)||void 0===t||t.call(g,i),y(),f("threeDsChallenge")),["onError","onChallengeError"].includes(null==i?void 0:i.code)&&(console.log(`challengeHandler ${null==i?void 0:i.code}`,(new Date).toLocaleTimeString()),null===(n=g.reject)||void 0===n||n.call(g,i),y(),f("threeDsChallenge")))},b={"01":["250px","400px"],"02":["390px","400px"],"03":["500px","600px"],"04":["600px","400px"],"05":["100%","100%"]};let E="";const C=({intent_id:e="",env:t="prod"})=>{if(!E.includes(e)){const n="prod"===t?"9ozphlqx":"45ssiuz3",i=document.createElement("script");E=`${e}${Date.now()}`,i.src=`https://h.online-metrix.net/fp/tags.js?org_id=${n}&session_id=${E}`,document.body.appendChild(i)}return E},D=t=>`https://${e[t]||"checkout.airwallex.com"}`,S=`/assets/bundle.${[0,2,40].join(".")}.min.js`,$=e=>{const t=document.createElement("script");t.src=`${e}${S}`;const n=document.head||document.body;if(!n)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return n.appendChild(t),t};exports.confirmPaymentIntent=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},exports.confirmPaymentIntentWithSavedCard=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},exports.createElement=(e,t)=>window.Airwallex?window.Airwallex.createElement(e,t):(console.error("Please loadAirwallex() before createElement();"),null),exports.createPaymentConsent=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},exports.createPaymentMethod=async(e,t)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,t);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},exports.destroyElement=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),exports.get3dsReturnUrl=n=>{const{env:i,checkoutOrigin:o}=n;return`${t[i||"prod"]}/api/v1/checkout/elements/3ds?origin=https://${e[i||"prod"]}&checkoutOrigin=${o||window.location.origin}`},exports.getBrowserInfo=e=>{const{navigator:t,screen:n}=window||{},{language:i}=t||{},{colorDepth:o,height:l,width:r}=n||{},{intent_id:a,env:s}=e||{};let d;return e&&(d=C({intent_id:a,env:s})),{device_id:d,screen_height:l,screen_width:r,screen_color_depth:o,language:i,timezone:(new Date).getTimezoneOffset(),browser:{java_enabled:window.navigator.javaEnabled(),javascript_enabled:!0,user_agent:t.userAgent}}},exports.getDeviceFingerprint=C,exports.getElement=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),exports.getGatewayUrl=D,exports.getPaymentIntent=async(e,t)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,t);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},exports.handle3ds=t=>{const{cardBin:n,next_action:i,authFormContainer:o,intent:l,challengeWindowSize:r,env:c}=t;return(({intent:e,gatewayUrl:t,cardBin:n,next_action:i,authFormContainer:o,componentType:l,challengeWindowSize:r})=>{var c;g.awaiting&&console.warn("Should wait previous 3ds flow finished before execute new one!"),console.log("threeDsHandler onChallenge type",(new Date).toLocaleTimeString()),w=document.getElementById(o||""),h=l,p=r,m=t,v=e,f("threeDsFrictionless"),s("threeDsFrictionless",new d(m,{code:"",type:"threeDsFrictionless",cardBin:n,next_action:i},{intent:v,origin:window.location.origin}));const u=document.createElement("div");return u.setAttribute("id","threeDsFrictionless"),document.body.appendChild(u),window.addEventListener("message",x),null===(c=a("threeDsFrictionless"))||void 0===c||c.mount(u),new Promise(((e,t)=>{g.resolver=e,g.reject=t,g.awaiting=!0}))})({gatewayUrl:`https://${e[c]}`,cardBin:n,intent:l,next_action:i,authFormContainer:o,componentType:"api",challengeWindowSize:r})},exports.init=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},exports.loadAirwallex=e=>Promise.resolve().then((()=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;const t=document.querySelector(`script[src="${S}"], script[src="${S}/"]`)||$(D((null==e?void 0:e.env)||"prod"));return new Promise(((n,i)=>{t.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),n(window.Airwallex)):i(new Error("Failed to load Airwallex on load event"))})),t.addEventListener("error",(()=>{i(new Error("Failed to load Airwallex scripts"))}))}))})),exports.loadAirwallexJs=$,exports.redirectToCheckout=e=>{window.Airwallex?window.Airwallex.redirectToCheckout(e):console.error("Please loadAirwallex() before redirectToCheckout();")};
3
- /* Airwallex @Charlie.Lang */
1
+ /* Airwallex Checkout Component Version [0.2.49] */
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},r=r=>`https://${e[r]||e.prod}`,o="/assets/elements.bundle.min.js",t=e=>{const r=document.createElement("script");r.src=`${e}${o}`;const t=document.head||document.body;if(!t)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return t.appendChild(r),r};exports.confirmPaymentIntent=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},exports.confirmPaymentIntentWithSavedCard=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},exports.createElement=(e,r)=>window.Airwallex?window.Airwallex.createElement(e,r):(console.error("Please loadAirwallex() before createElement();"),null),exports.createPaymentConsent=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},exports.createPaymentMethod=async(e,r)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,r);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},exports.destroyElement=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),exports.get3dsReturnUrl=e=>window.Airwallex.get3dsReturnUrl(e),exports.getBrowserInfo=e=>window.Airwallex.getBrowserInfo(e),exports.getDeviceFingerprint=e=>window.Airwallex.getDeviceFingerprint(e),exports.getElement=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),exports.getGatewayUrl=r,exports.getPaymentIntent=async(e,r)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,r);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},exports.handle3ds=e=>window.Airwallex.handle3ds(e),exports.init=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},exports.loadAirwallex=e=>Promise.resolve().then((()=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;const n=document.querySelector(`script[src="${o}"], script[src="${o}/"]`)||t(r((null==e?void 0:e.env)||"prod"));return new Promise(((r,o)=>{n.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),r(window.Airwallex)):o(new Error("Failed to load Airwallex on load event"))})),n.addEventListener("error",(()=>{o(new Error("Failed to load Airwallex scripts"))}))}))})),exports.loadAirwallexJs=t,exports.redirectToCheckout=e=>{window.Airwallex?window.Airwallex.redirectToCheckout(e):console.error("Please loadAirwallex() before redirectToCheckout();")};
4
3
  //# sourceMappingURL=airwallex.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"airwallex.cjs.js","sources":["../../src/util.ts","../../src/element.ts","../../src/airwallex.ts","../../src/threeDsFrictionless.ts","../../src/threeDsChallenge.ts","../../src/handle3dsFlow.ts","../../src/fraud.ts","../../src/npmPackage/index.ts"],"sourcesContent":["export const simulateFormSubmit = (data: { [k: string]: string }, action: string): void => {\n const formEle = document.createElement('form');\n formEle.setAttribute('method', 'post');\n formEle.setAttribute('style', 'height: 0; overflow: hidden;');\n formEle.action = action;\n Object.keys(data || {}).forEach((key: string) => {\n const inputEle = document.createElement('input');\n inputEle.type = 'hidden';\n inputEle.name = key;\n inputEle.value = data[key];\n formEle.appendChild(inputEle);\n });\n const submitBtn = document.createElement('input');\n submitBtn.type = 'submit';\n formEle.appendChild(submitBtn);\n document.body.appendChild(formEle);\n submitBtn.click();\n};\n\ntype eventHandlerType = (event: MessageEvent) => void;\n\nexport const useMessageListener = (eventHandler: eventHandlerType): void => {\n window.addEventListener('message', (event: MessageEvent) => {\n if (window.ReactNativeWebView) {\n window.ReactNativeWebView.postMessage(JSON.stringify(event.data));\n }\n\n eventHandler(event);\n });\n};\n\nexport const ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\nexport const ENV_CHECKOUT_SERVER_HOST = {\n prod: 'https://pci-api.airwallex.com',\n demo: 'https://pci-api-demo.airwallex.com',\n staging: 'https://pci-api-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'https://pci-api-qa.airwallex.com',\n preview: 'https://pci-api-preview.airwallex.com',\n dev: 'http://localhost:8080',\n};\n","import { Element, ElementError } from '../types/element';\nimport { useMessageListener } from './util';\nimport { Intent } from '../types/cardNumber';\n\nexport class ElementBase implements Element {\n gatewayUrl: string;\n options?: Element['options'];\n iframe: HTMLIFrameElement | null;\n domElement: null | HTMLElement;\n\n constructor(gatewayUrl: string, options?: Element['options']) {\n this.domElement = null;\n this.gatewayUrl = gatewayUrl;\n this.options = options;\n this.iframe = window.document.createElement('iframe');\n this.iframe.setAttribute('frameborder', '0');\n this.iframe.setAttribute('allowtransparency', 'true');\n this.iframe.setAttribute('importance', 'high');\n this.iframe.setAttribute('scrolling', 'no');\n this.iframe.setAttribute('allowpaymentrequest', 'true');\n this.iframe?.setAttribute(\n 'style',\n `\n height: 0;\n width: 100%;\n display: block;\n `,\n );\n useMessageListener((event: MessageEvent) => {\n // exist for the old user, already handle onReady event in individual Element\n if (event.origin === this.gatewayUrl && event.isTrusted && event.data?.code === 'onReady') {\n const customEvent = new CustomEvent(event.data?.code, {\n detail: {\n type: event.data?.type,\n },\n bubbles: true,\n composed: true,\n });\n window.document.dispatchEvent(customEvent);\n }\n });\n }\n\n addResizeListener(type: string): void {\n window.addEventListener('message', (event: MessageEvent) => {\n if (event.origin === this.gatewayUrl && event.isTrusted) {\n if (event.data?.code === 'onResize' && type === event.data?.type) {\n const styleAttribute = this.iframe?.style;\n if (styleAttribute) {\n styleAttribute.height = `${event.data?.height}px`;\n }\n }\n }\n });\n }\n\n mount(domElement: string | HTMLElement): null | HTMLElement {\n if (typeof domElement !== 'string') {\n if (domElement?.hasChildNodes()) {\n domElement.innerHTML = '';\n }\n this.iframe && domElement.appendChild(this.iframe);\n this.domElement = domElement;\n return domElement;\n } else {\n const getDomElement = window.document.getElementById(domElement);\n if (getDomElement?.hasChildNodes()) {\n getDomElement.innerHTML = '';\n }\n this.iframe && getDomElement?.appendChild(this.iframe);\n if (getDomElement) {\n this.domElement = getDomElement;\n }\n return getDomElement;\n }\n }\n\n blur(): void {\n this.iframe?.contentWindow?.postMessage({ code: 'blur' }, this.gatewayUrl);\n }\n\n clear(): void {\n this.iframe?.contentWindow?.postMessage({ code: 'clear' }, this.gatewayUrl);\n }\n\n destroy(): void {\n this.clear();\n this.iframe?.remove();\n this.iframe = null;\n }\n\n focus(): void {\n this.iframe?.contentWindow?.postMessage({ code: 'focus' }, this.gatewayUrl);\n }\n\n unmount(): void {\n this.clear();\n this.iframe && this.domElement?.removeChild(this.iframe);\n }\n\n update(options?: Element['options']): void {\n this.options = { ...this.options, ...options };\n this.iframe?.contentWindow?.postMessage({ code: 'update', options }, this.gatewayUrl);\n }\n async confirm(): Promise<Intent | null> {\n throw new Error('Confirm is not supported in ElementBase');\n }\n success(value: Intent): void {\n throw new Error(`Call success with ${value.id} is not supported in ElementBase`);\n }\n fail(error: ElementError): void {\n throw new Error(`Call fail with ${error.code}: ${error.message} is not supported in ElementBase`);\n }\n}\n","import { ElementBase } from './element';\nimport { ElementType } from '../types/element';\nimport { CardNumberElement } from './cardNumber';\nimport { ExpiryElement } from './expiry';\nimport { CvcElement } from './cvc';\nimport { PaymentRequestButtonElement } from './paymentRequestButton';\nimport { DropInElement } from './dropIn';\nimport { FullFeaturedCardElement } from './fullFeaturedCard';\nimport { CardElement } from './card';\nimport { WechatElement } from './wechat';\nimport { QrcodeElement } from './qrcode';\nimport { RedirectElement } from './redirect';\nimport { processQueryParams } from './processParams';\nimport { getGatewayUrl } from './npmPackage';\n\nimport {\n InitOptions,\n HostPaymentPage,\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n} from '../types/airwallex';\n\nimport { FullFeaturedCardElementOptions } from '../types/element';\nimport { RedirectElementOptions } from '../types/redirectElement';\nimport { DropInElementOptions } from '../types/dropInElement';\n\nexport const ElementList = [\n 'cardNumber',\n 'expiry',\n 'cvc',\n 'paymentRequestButton',\n 'card',\n 'wechat',\n 'qrcode',\n 'redirect',\n 'dropIn',\n 'fullFeaturedCard',\n];\n\nexport const ThreeDsElementList = <const>['threeDsFrictionless', 'threeDsChallenge'];\nexport type ExtendElementType = ElementType | typeof ThreeDsElementList[number];\nexport const ExtentElementList = [...ElementList, ...ThreeDsElementList];\n\nexport interface Config {\n gatewayUrl: string;\n options?: InitOptions;\n}\n\nexport interface Elements {\n cardNumber: ElementBase | null;\n expiry: ElementBase | null;\n cvc: ElementBase | null;\n threeDsFrictionless: ElementBase | null;\n threeDsChallenge: ElementBase | null;\n paymentRequestButton: ElementBase | null;\n card: ElementBase | null;\n wechat: ElementBase | null;\n qrcode: ElementBase | null;\n redirect: ElementBase | null;\n dropIn: ElementBase | null;\n fullFeaturedCard: ElementBase | null;\n}\n\nexport const CONFIG: Config = {\n gatewayUrl: '',\n options: {} as InitOptions,\n};\n\nexport const ELEMENTS: Elements = {\n cardNumber: null,\n expiry: null,\n cvc: null,\n threeDsFrictionless: null,\n threeDsChallenge: null,\n paymentRequestButton: null,\n card: null,\n wechat: null,\n qrcode: null,\n redirect: null,\n dropIn: null,\n fullFeaturedCard: null,\n};\n\nexport const init: typeof initFn = (options) => {\n if (options?.env || !CONFIG.gatewayUrl) {\n CONFIG.gatewayUrl = getGatewayUrl(options?.env || 'prod');\n }\n CONFIG.options = options;\n};\n\nexport type Key = Exclude<keyof HostPaymentPage, 'id' | 'intent_id' | 'host'>;\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n const { env, ...restProps } = props;\n const parameters = processQueryParams(restProps);\n const { id, ...rest } = parameters || {};\n const queryParamsKeys = Object.keys(rest) as Key[];\n const paramsArray: string[] = [];\n queryParamsKeys.forEach((key: Key) => {\n paramsArray.push(`${key}=${rest[key]}`);\n });\n const redirectUrl =\n props.mode === 'recurring'\n ? `${getGatewayUrl(env || 'prod')}/#/standalone/recurring?${paramsArray.join('&')}`\n : `${getGatewayUrl(env || 'prod')}/#/standalone/checkout/${id || rest?.intent_id}?${paramsArray.join('&')}`;\n window.location.href = redirectUrl;\n};\n\nexport const createElement: typeof createElementFn = (type, options) => {\n const newOptions = options ?? { origin: '' };\n if (!newOptions.origin) {\n newOptions.origin = CONFIG.options?.origin;\n }\n if (!ElementList.includes(type)) {\n console.warn(`createElement with type: ${type} not support!`);\n return null;\n }\n if (type === 'cardNumber') {\n ELEMENTS[type] = new CardNumberElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'card') {\n ELEMENTS[type] = new CardElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'fullFeaturedCard') {\n ELEMENTS[type] = new FullFeaturedCardElement(CONFIG.gatewayUrl, newOptions as FullFeaturedCardElementOptions);\n return ELEMENTS[type];\n } else if (type === 'wechat') {\n ELEMENTS[type] = new WechatElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'qrcode') {\n ELEMENTS[type] = new QrcodeElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'redirect') {\n ELEMENTS[type] = new RedirectElement(CONFIG.gatewayUrl, newOptions as RedirectElementOptions);\n return ELEMENTS[type];\n } else if (type === 'paymentRequestButton') {\n ELEMENTS[type] = new PaymentRequestButtonElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'dropIn') {\n ELEMENTS[type] = new DropInElement(CONFIG.gatewayUrl, (newOptions as unknown) as DropInElementOptions);\n return ELEMENTS[type];\n } else if (type === 'expiry' || type === 'cvc') {\n ELEMENTS[type] =\n type === 'expiry'\n ? new ExpiryElement(CONFIG.gatewayUrl, newOptions)\n : new CvcElement(CONFIG.gatewayUrl, newOptions);\n\n window.addEventListener('message', (event: MessageEvent) => {\n // Communicate cvc and expiry to cardNumber element\n if (\n event.origin === CONFIG.gatewayUrl &&\n event.isTrusted &&\n type === event.data?.type &&\n event.data?.code === 'onChange'\n ) {\n ELEMENTS.cardNumber?.iframe?.contentWindow?.postMessage(\n { code: `update_${event.data?.type}`, data: event.data },\n CONFIG.gatewayUrl,\n );\n }\n });\n return ELEMENTS[type];\n }\n\n return null;\n};\n\nexport const destroyElement = (type: ExtendElementType): boolean => {\n if (ExtentElementList.includes(type)) {\n ELEMENTS[type]?.destroy();\n ELEMENTS[type] = null;\n return true;\n } else {\n console.warn(`destroyElement with type: ${type} not support!`);\n return false;\n }\n};\n\nexport const getElement = (type: ExtendElementType): ElementBase | null => {\n if (ExtentElementList.includes(type)) {\n return ELEMENTS[type];\n } else {\n console.warn(`getElement with type: ${type} not support!`);\n return null;\n }\n};\n\nexport const setElement = (type: ExtendElementType, element: ElementBase): boolean => {\n if (ExtentElementList.includes(type)) {\n ELEMENTS[type] = element;\n return true;\n } else {\n console.warn(`destroyElement with type: ${type} not support!`);\n return false;\n }\n};\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n console.info(`Confirm intent ${data?.intent_id || data?.id} with client secret: ${data?.client_secret}`);\n if (data?.element) {\n return (data?.element as CardNumberElement).confirm(data);\n } else {\n console.warn('Card number element must be provided for card payment confirm!');\n return false;\n }\n};\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n console.info(`Confirm intent ${data?.intent_id || data?.id} with client secret: ${data?.client_secret}`);\n if (data?.element && data?.methodId) {\n return (data?.element as CvcElement).confirm(data);\n } else {\n console.warn('Payment method id must be provided for cvc payment confirm!');\n return false;\n }\n};\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n console.info(`Create payment method with client secret: ${client_secret}`);\n if (data?.element) {\n return (data?.element as CardNumberElement).createPaymentMethod({\n ...data,\n client_secret,\n });\n } else {\n console.warn('Either payment method id or element must be provided for payment method create!');\n return false;\n }\n};\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n console.info(`Create payment consent with client secret: ${data.client_secret}`);\n if (data?.element) {\n return (data?.element as CardElement).createPaymentConsent(data);\n } else {\n console.warn('Either payment method id or element must be provided for create payment consent!');\n return false;\n }\n};\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n return (ELEMENTS.cardNumber as CardNumberElement)?.getPaymentIntent(id, client_secret) || false;\n};\n","import { ElementBase } from './element';\nimport { ElementOptions, ExtendEventDetail } from '../types/element';\nimport { Intent } from '../types/cardNumber';\nimport { CONFIG } from './airwallex';\n\nexport class ThreeDsFrictionlessElement extends ElementBase {\n confirmResponse: ExtendEventDetail;\n\n constructor(gatewayUrl: string, confirmResponse: ExtendEventDetail, options?: ElementOptions & { intent: Intent }) {\n super(gatewayUrl, options);\n this.confirmResponse = confirmResponse;\n this.iframe?.setAttribute(\n 'src',\n `${gatewayUrl}/#/elements/3ds-frictionless?options=${encodeURIComponent(JSON.stringify(this.options))}&lang=${\n CONFIG.options?.locale\n }`,\n );\n this.iframe?.setAttribute('name', 'Airwallex 3DS frictionless iframe');\n this.iframe?.setAttribute('title', 'Airwallex 3DS frictionless iframe');\n window.addEventListener('message', (event: MessageEvent) => {\n if (\n event.origin === this.gatewayUrl &&\n event.isTrusted &&\n event.data?.code === 'onReady' &&\n event.data?.type === 'threeDsFrictionless'\n ) {\n this.iframe?.contentWindow?.postMessage({ code: 'update', data: this.confirmResponse }, this.gatewayUrl);\n }\n });\n }\n async confirm(): Promise<Intent | null> {\n this.iframe?.contentWindow?.postMessage(\n {\n code: 'confirm',\n data: this.confirmResponse,\n },\n this.gatewayUrl,\n );\n return null;\n }\n}\n","import { ElementBase } from './element';\nimport { ElementOptions, ExtendEventDetail } from '../types/element';\nimport { Intent } from '../types/cardNumber';\nimport { CHALLENGE_WINDOW_SIZE_MAP } from './fraud';\n\nexport class ThreeDsChallengeElement extends ElementBase {\n confirmResponse: ExtendEventDetail;\n\n constructor(\n gatewayUrl: string,\n confirmResponse: ExtendEventDetail,\n options?: ElementOptions & { useDefaultStyle: boolean; customizeChallengeWindowSize?: string; intent: Intent },\n ) {\n super(gatewayUrl, options);\n this.confirmResponse = confirmResponse;\n // If provided predefined challenge window size, then use it, otherwise use '05' which is ['100%', '100%']\n const challengeWindowSize =\n options?.customizeChallengeWindowSize && CHALLENGE_WINDOW_SIZE_MAP[options?.customizeChallengeWindowSize]\n ? CHALLENGE_WINDOW_SIZE_MAP[options?.customizeChallengeWindowSize]\n : CHALLENGE_WINDOW_SIZE_MAP['05'];\n // if merchant provided the popupWidth when build element, then use it, otherwise use the width of challengeWindowSize\n const authPopupWidth = options?.style?.popupWidth ? `${options?.style?.popupWidth}px` : challengeWindowSize[0];\n // if merchant provided the popupHeight when build element, then use it, otherwise use the height of challengeWindowSize\n const authPopupHeight = options?.style?.popupHeight ? `${options?.style?.popupHeight}px` : challengeWindowSize[1];\n this.iframe?.setAttribute(\n 'src',\n `${gatewayUrl}/#/elements/3ds-challenge?options=${encodeURIComponent(JSON.stringify(this.options))}`,\n );\n this.iframe?.setAttribute('name', 'Airwallex 3DS challenge iframe');\n this.iframe?.setAttribute('title', 'Airwallex 3DS challenge iframe');\n this.iframe?.setAttribute('scrolling', 'yes');\n this.iframe?.setAttribute(\n 'style',\n `\n background: #fff;\n width: ${authPopupWidth};\n height: ${authPopupHeight};\n position: ${options?.useDefaultStyle ? 'absolute' : 'relative'};\n top: ${options?.useDefaultStyle ? '50%' : '0'};\n left: ${options?.useDefaultStyle ? '50%' : '0'};\n transform: ${options?.useDefaultStyle ? 'translate(-50%, -50%)' : 'none'};\n border-radius: ${options?.useDefaultStyle ? '4px' : '0'};\n `,\n );\n window.addEventListener('message', (event: MessageEvent) => {\n if (\n event.origin === this.gatewayUrl &&\n event.isTrusted &&\n event.data?.code === 'onReady' &&\n event.data?.type === 'threeDsChallenge'\n ) {\n this.iframe?.contentWindow?.postMessage({ code: 'update', data: this.confirmResponse }, this.gatewayUrl);\n }\n });\n }\n async confirm(): Promise<Intent | null> {\n this.iframe?.contentWindow?.postMessage(\n {\n code: 'confirm',\n data: this.confirmResponse,\n },\n this.gatewayUrl,\n );\n return null;\n }\n}\n","import { ThreeDsFrictionlessElement } from './threeDsFrictionless';\nimport { ThreeDsChallengeElement } from './threeDsChallenge';\nimport { destroyElement, setElement, getElement } from './airwallex';\nimport { ElementType, EventCode, ElementError, ExtendEventDetail } from '../types/element';\nimport { NextAction } from '../types/fraud';\nimport { Intent } from '../types/cardNumber';\n\ntype Resolver = (value: ExtendEventDetail | PromiseLike<ExtendEventDetail>) => void;\ntype Reject = (error?: ElementError) => void;\n\ntype ThreeDsPromiseType = {\n resolver: Resolver | null;\n reject: Reject | null;\n awaiting: boolean;\n};\n\nconst threeDsFrictionlessType = 'threeDsFrictionless';\nconst threeDsChallengeType = 'threeDsChallenge';\n/**\n * These variables are used in element iframe, frictionless iframe and challenge iframe\n * Different iframe communicate with events, so use the global variable instead of inject the events.\n */\n// The div container that contains the iframe if merchant not provided\nlet challengeDiv: HTMLElement;\n// The error handler for 3ds result\nlet customizeAuthFormContainer: HTMLElement | null;\n// The container that contains the iframe which is provided by merchant\nlet type: ExtendElementType | 'hpp' | 'api';\n// The customize popup width provided by merchant when mount element\nlet customizePopupWidth: number | undefined;\n// The customize popup height provided by merchant when mount element\nlet customizePopupHeight: number | undefined;\n// The customize challenge window size by merchant when handle 3ds\nlet customizeChallengeWindowSize: string | undefined;\n// The gateway url of the gateway url for build iframe\nlet customizeGatewayUrl: string;\n// The intent that you would like to confirm\nlet intentData: Intent;\n// The resolver for 3ds flow result\nconst threeDsPromise: ThreeDsPromiseType = {\n resolver: null,\n reject: null,\n awaiting: false,\n};\n\nconst ThreeDsElementList = ['threeDsFrictionless', 'threeDsChallenge'] as const;\nexport type ExtendElementType = ElementType | typeof ThreeDsElementList[number];\nconst ExtendEventList = [\n 'onResize',\n 'onRedirect',\n 'onComplete',\n 'onChallenge',\n 'onChallengeSuccess',\n 'onChallengeError',\n 'onIntentRetrieved',\n 'onIntentRetrievedError',\n 'onPaymentMethodCreated',\n 'onPaymentMethodCreatedError',\n] as const;\nexport type ExtendEventCode = EventCode | typeof ExtendEventList[number];\n\n// Clear the 3DS iframe\nexport const clear3Ds = (type: typeof threeDsFrictionlessType | typeof threeDsChallengeType): void => {\n document.querySelector(`#${type}`)?.remove();\n if (type === threeDsFrictionlessType) {\n destroyElement(threeDsFrictionlessType);\n } else {\n destroyElement(threeDsChallengeType);\n }\n};\n\n// Clear 3ds Promis\nexport const clearThreeDsPromise = (): void => {\n threeDsPromise.awaiting = false;\n threeDsPromise.resolver = null;\n threeDsPromise.reject = null;\n};\n\n// HPP handle 3ds success\nexport const onHppSuccess = (value: ExtendEventDetail | undefined): void => {\n const customEvent = new CustomEvent('on3dsSuccess', {\n detail: value,\n bubbles: true,\n composed: true,\n });\n window.document.dispatchEvent(customEvent);\n};\n\n// HPP handle 3ds error\nexport const onHppError = (error?: ElementError): void => {\n const customEvent = new CustomEvent('on3dsError', {\n detail: {\n error,\n },\n bubbles: true,\n composed: true,\n });\n window.document.dispatchEvent(customEvent);\n};\n\ninterface ThreeDsHandlerProps {\n intent: Intent;\n gatewayUrl: string;\n cardBin: string;\n next_action: NextAction;\n authFormContainer?: string;\n componentType: ExtendElementType | 'hpp' | 'api';\n challengeWindowSize?: string;\n}\n\n/**\n * Both the handle3ds function(for api integration) and threeDsListener(for elements integration) would go through this function\n * @return {Promise<ExtendEventDetail>} Promise type which will resolve ExtendEventDetail type when success\n */\nexport const threeDsHandler = ({\n intent,\n gatewayUrl,\n cardBin,\n next_action,\n authFormContainer,\n componentType,\n challengeWindowSize,\n}: ThreeDsHandlerProps): Promise<ExtendEventDetail> => {\n if (threeDsPromise.awaiting) {\n console.warn('Should wait previous 3ds flow finished before execute new one!');\n }\n console.log('threeDsHandler onChallenge type', new Date().toLocaleTimeString());\n customizeAuthFormContainer = document.getElementById(authFormContainer || '');\n type = componentType;\n customizeChallengeWindowSize = challengeWindowSize;\n customizeGatewayUrl = gatewayUrl;\n intentData = intent;\n\n clear3Ds(threeDsFrictionlessType);\n setElement(\n threeDsFrictionlessType,\n new ThreeDsFrictionlessElement(\n customizeGatewayUrl,\n {\n code: '',\n type: threeDsFrictionlessType,\n cardBin,\n next_action,\n },\n {\n intent: intentData,\n origin: window.location.origin,\n },\n ),\n );\n const frictionlessDiv = document.createElement('div');\n frictionlessDiv.setAttribute('id', threeDsFrictionlessType);\n document.body.appendChild(frictionlessDiv);\n window.addEventListener('message', frictionlessHandler);\n getElement(threeDsFrictionlessType)?.mount(frictionlessDiv);\n\n return new Promise((resolve: Resolver, reject: Reject) => {\n threeDsPromise.resolver = resolve;\n threeDsPromise.reject = reject;\n threeDsPromise.awaiting = true;\n });\n};\n\n/**\n * Setup the frictionless iframe listeners\n * @param {CustomEvent | MessageEvent} event the event received from the frictionless iframe\n */\nconst frictionlessHandler = (event: CustomEvent | MessageEvent) => {\n const eventData = 'data' in event ? event.data : event.detail;\n const isHppOrApi = ['hpp', 'api'].includes(type);\n const element = isHppOrApi ? null : getElement(type as ExtendElementType);\n const gatewayUrl = element?.gatewayUrl || window.location.origin;\n const eventIsTrusted = ('data' in event && event.origin === gatewayUrl && event.isTrusted) || isHppOrApi;\n\n if (eventIsTrusted && eventData?.type === threeDsFrictionlessType) {\n clear3Ds(threeDsChallengeType);\n if (eventData?.code === 'onSuccess') {\n console.log('frictionlessHandler onSuccess', new Date().toLocaleTimeString());\n threeDsPromise.resolver?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsFrictionlessType);\n }\n if (['onError', 'onChallengeError'].includes(eventData?.code)) {\n console.log(`frictionlessHandler ${eventData?.code}`, new Date().toLocaleTimeString());\n threeDsPromise.reject?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsFrictionlessType);\n }\n if (eventData?.code === 'onChallenge') {\n console.log('frictionlessHandler onChallenge threeDsFrictionlessType', new Date().toLocaleTimeString());\n clear3Ds(threeDsFrictionlessType);\n if (!customizeAuthFormContainer) {\n challengeDiv = document.createElement('div');\n challengeDiv.setAttribute('id', threeDsChallengeType);\n challengeDiv.setAttribute(\n 'style',\n `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 0;\n z-index: 1500;\n overflow: hidden;\n background: rgba(0, 0, 0, 0.75);\n `,\n );\n document.body.appendChild(challengeDiv);\n } else {\n challengeDiv = customizeAuthFormContainer;\n }\n setElement(\n threeDsChallengeType,\n new ThreeDsChallengeElement(customizeGatewayUrl, eventData as ExtendEventDetail, {\n origin: window.location.origin,\n style: {\n popupWidth: customizePopupWidth,\n popupHeight: customizePopupHeight,\n },\n useDefaultStyle: customizeAuthFormContainer === null,\n customizeChallengeWindowSize,\n intent: intentData,\n }),\n );\n window.addEventListener('message', challengeHandler);\n getElement(threeDsChallengeType)?.mount(challengeDiv);\n }\n }\n};\n\n/**\n * Setup the challenge iframe listeners\n * @param {CustomEvent | MessageEvent} event the event received from the challenge iframe\n */\nconst challengeHandler = (event: CustomEvent | MessageEvent) => {\n const eventData = 'data' in event ? event.data : event.detail;\n const isHppOrApi = ['hpp', 'api'].includes(type);\n const element = isHppOrApi ? null : getElement(type as ExtendElementType);\n const gatewayUrl = element?.gatewayUrl || window.location.origin;\n const eventIsTrusted = ('data' in event && event.origin === gatewayUrl && event.isTrusted) || isHppOrApi;\n\n if (eventIsTrusted && eventData?.type === threeDsChallengeType) {\n if (eventData?.code === 'onReady') {\n console.log('challengeHandler onReady', new Date().toLocaleTimeString());\n setTimeout(() => {\n challengeDiv.style.height = '100%';\n }, 2000);\n }\n if (eventData?.code === 'onChallengeSuccess') {\n challengeDiv.style.height = '0';\n }\n if (eventData?.code === 'onSuccess') {\n console.log('challengeHandler onSuccess', new Date().toLocaleTimeString());\n threeDsPromise.resolver?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsChallengeType);\n }\n if (['onError', 'onChallengeError'].includes(eventData?.code)) {\n console.log(`challengeHandler ${eventData?.code}`, new Date().toLocaleTimeString());\n threeDsPromise.reject?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsChallengeType);\n }\n }\n};\n\ninterface Handle3dsFlowProps {\n type: ElementType | 'hpp';\n popupWidth?: number;\n popupHeight?: number;\n authFormContainer?: string;\n}\n\nexport const handle3dsFlow = ({ type, popupWidth, popupHeight, authFormContainer }: Handle3dsFlowProps): void => {\n customizePopupWidth = popupWidth;\n customizePopupHeight = popupHeight;\n\n /**\n * This function will listener to the message event from elements including HPP\n * @param {CustomEvent | MessageEvent} event add listener to handle event from elements\n */\n const threeDsListener = async (event: CustomEvent | MessageEvent) => {\n const eventData = 'data' in event ? event.data : event.detail;\n const isHpp = type === 'hpp';\n const element = isHpp ? null : getElement(type as ExtendElementType);\n const gatewayUrl = element?.gatewayUrl || window.location.origin;\n const eventIsTrusted = ('data' in event && event.origin === gatewayUrl && event.isTrusted) || isHpp;\n\n if (eventIsTrusted && eventData?.type === type && eventData?.code === 'onChallenge') {\n const { cardBin, next_action, intent } = eventData;\n try {\n const confirmResult = await threeDsHandler({\n gatewayUrl,\n cardBin,\n intent,\n next_action,\n authFormContainer,\n componentType: type,\n });\n\n if (type === 'hpp') {\n onHppSuccess(confirmResult);\n } else {\n if (confirmResult?.intent) {\n element?.success(confirmResult?.intent);\n }\n element?.iframe?.contentWindow?.postMessage({ code: 'on3dsSuccess', confirmResult }, gatewayUrl);\n }\n\n window.removeEventListener('message', threeDsListener);\n window.removeEventListener('message', frictionlessHandler);\n window.removeEventListener('message', challengeHandler);\n } catch (error) {\n if (type === 'hpp') {\n onHppError(error);\n } else {\n error && element?.fail(error);\n element?.iframe?.contentWindow?.postMessage({ code: 'on3dsError', error }, gatewayUrl);\n }\n\n window.removeEventListener('message', challengeHandler);\n }\n }\n };\n\n window.addEventListener('message', threeDsListener);\n};\n","import {\n Handle3dsRequest,\n Get3dsReturnUrlRequest,\n getBrowserInfo as getBrowserInfoFn,\n getDeviceFingerprint as getDeviceFingerprintFn,\n handle3ds as handle3dsFn,\n get3dsReturnUrl as get3dsReturnUrlFn,\n} from '../types/fraud';\nimport { threeDsHandler } from './handle3dsFlow';\nimport { ENV_HOST, ENV_CHECKOUT_SERVER_HOST } from './util';\n\nexport const CHALLENGE_WINDOW_SIZE_MAP: { [key: string]: [string, string] } = {\n '01': ['250px', '400px'],\n '02': ['390px', '400px'],\n '03': ['500px', '600px'],\n '04': ['600px', '400px'],\n '05': ['100%', '100%'],\n};\n\nexport const getBrowserInfo: typeof getBrowserInfoFn = (fingerprintRequest) => {\n const { navigator, screen } = window || {};\n const { language } = navigator || {};\n const { colorDepth, height, width } = screen || {};\n const { intent_id, env } = fingerprintRequest || {};\n let device_id;\n if (fingerprintRequest) {\n device_id = getDeviceFingerprint({ intent_id, env });\n }\n\n return {\n device_id,\n screen_height: height,\n screen_width: width,\n screen_color_depth: colorDepth,\n language: language,\n timezone: new Date().getTimezoneOffset(),\n browser: {\n java_enabled: window.navigator.javaEnabled(),\n javascript_enabled: true,\n user_agent: navigator.userAgent,\n },\n };\n};\n\nlet fraudSessionId = '';\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = ({ intent_id = '', env = 'prod' }) => {\n if (!fraudSessionId.includes(intent_id)) {\n const ORG_ID = env === 'prod' ? '9ozphlqx' : '45ssiuz3';\n const script = document.createElement('script');\n fraudSessionId = `${intent_id}${Date.now()}`;\n script.src = `https://h.online-metrix.net/fp/tags.js?org_id=${ORG_ID}&session_id=${fraudSessionId}`;\n document.body.appendChild(script);\n }\n\n return fraudSessionId;\n};\n\nexport const get3dsReturnUrl: typeof get3dsReturnUrlFn = (props: Get3dsReturnUrlRequest) => {\n const { env, checkoutOrigin } = props;\n return `${ENV_CHECKOUT_SERVER_HOST[env || 'prod']}/api/v1/checkout/elements/3ds?origin=https://${\n ENV_HOST[env || 'prod']\n }&checkoutOrigin=${checkoutOrigin || window.location.origin}`;\n};\n\nexport const handle3ds: typeof handle3dsFn = (props: Handle3dsRequest) => {\n const { cardBin, next_action, authFormContainer, intent, challengeWindowSize, env } = props;\n return threeDsHandler({\n gatewayUrl: `https://${ENV_HOST[env]}`,\n cardBin,\n intent,\n next_action,\n authFormContainer,\n componentType: 'api',\n challengeWindowSize,\n });\n};\n","import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../../types/airwallex';\nexport { getBrowserInfo, getDeviceFingerprint, get3dsReturnUrl, handle3ds } from '../../src/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../../types/index';\nimport { ENV_HOST } from '../util';\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || 'checkout.airwallex.com'}`;\n\nconst version = [process.env.version_major, process.env.version_minor, process.env.version_patch].join('.');\n\nconst STATIC_JS_URL = `/assets/bundle.${version}.min.js`;\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\nexport const loadAirwallex: typeof loadAirwallexFn = (options) => {\n return Promise.resolve().then(() => {\n if (typeof window === 'undefined') {\n return null;\n }\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n });\n });\n });\n};\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n window.Airwallex.redirectToCheckout(props);\n }\n};\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","ENV_CHECKOUT_SERVER_HOST","ElementBase","[object Object]","gatewayUrl","options","eventHandler","this","domElement","iframe","window","document","createElement","setAttribute","event","origin","isTrusted","data","code","customEvent","CustomEvent","detail","type","bubbles","composed","dispatchEvent","addEventListener","ReactNativeWebView","postMessage","JSON","stringify","styleAttribute","style","height","hasChildNodes","innerHTML","appendChild","getDomElement","getElementById","contentWindow","clear","remove","removeChild","Error","value","id","error","message","ExtentElementList","CONFIG","ELEMENTS","cardNumber","expiry","cvc","threeDsFrictionless","threeDsChallenge","paymentRequestButton","card","wechat","qrcode","redirect","dropIn","fullFeaturedCard","destroyElement","includes","destroy","console","warn","getElement","setElement","element","ThreeDsFrictionlessElement","confirmResponse","super","encodeURIComponent","locale","ThreeDsChallengeElement","challengeWindowSize","customizeChallengeWindowSize","CHALLENGE_WINDOW_SIZE_MAP","authPopupWidth","popupWidth","authPopupHeight","popupHeight","useDefaultStyle","challengeDiv","customizeAuthFormContainer","customizeGatewayUrl","intentData","threeDsPromise","resolver","reject","awaiting","clear3Ds","querySelector","clearThreeDsPromise","frictionlessHandler","eventData","isHppOrApi","location","log","Date","toLocaleTimeString","body","customizePopupWidth","customizePopupHeight","intent","challengeHandler","mount","setTimeout","01","02","03","04","05","fraudSessionId","getDeviceFingerprint","intent_id","env","ORG_ID","script","now","src","getGatewayUrl","STATIC_JS_URL","join","loadAirwallexJs","headOrBody","head","async","Airwallex","confirmPaymentIntent","err","confirmPaymentIntentWithSavedCard","createPaymentConsent","client_secret","createPaymentMethod","props","checkoutOrigin","fingerprintRequest","navigator","screen","language","colorDepth","width","device_id","screen_height","screen_width","screen_color_depth","timezone","getTimezoneOffset","browser","java_enabled","javaEnabled","javascript_enabled","user_agent","userAgent","getPaymentIntent","cardBin","next_action","authFormContainer","componentType","frictionlessDiv","Promise","resolve","threeDsHandler","init","then","redirectToCheckout"],"mappings":";oEAqBO,MAUMA,EAAW,CACtBC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAGMC,EAA2B,CACtCN,KAAM,gCACNC,KAAM,qCACNC,QAAS,wCAKTC,GAAI,mCACJC,QAAS,wCACTC,IAAK,+BClDME,EAMXC,YAAYC,EAAoBC,SDWCC,ECV/BC,KAAKC,WAAa,KAClBD,KAAKH,WAAaA,EAClBG,KAAKF,QAAUA,EACfE,KAAKE,OAASC,OAAOC,SAASC,cAAc,UAC5CL,KAAKE,OAAOI,aAAa,cAAe,KACxCN,KAAKE,OAAOI,aAAa,oBAAqB,QAC9CN,KAAKE,OAAOI,aAAa,aAAc,QACvCN,KAAKE,OAAOI,aAAa,YAAa,MACtCN,KAAKE,OAAOI,aAAa,sBAAuB,kBAChDN,KAAKE,uBAAQI,aACX,QACA,+EDD6BP,ECOXQ,cAElB,GAAIA,EAAMC,SAAWR,KAAKH,YAAcU,EAAME,WAAkC,uBAArBF,EAAMG,2BAAMC,MAAoB,CACzF,MAAMC,EAAc,IAAIC,sBAAYN,EAAMG,2BAAMC,KAAM,CACpDG,OAAQ,CACNC,eAAMR,EAAMG,2BAAMK,MAEpBC,SAAS,EACTC,UAAU,IAEZd,OAAOC,SAASc,cAAcN,KDhBpCT,OAAOgB,iBAAiB,WAAYZ,IAC9BJ,OAAOiB,oBACTjB,OAAOiB,mBAAmBC,YAAYC,KAAKC,UAAUhB,EAAMG,OAG7DX,EAAaQ,MCgBfX,kBAAkBmB,GAChBZ,OAAOgB,iBAAiB,WAAYZ,gBAClC,GAAIA,EAAMC,SAAWR,KAAKH,YAAcU,EAAME,WACnB,wBAArBF,EAAMG,2BAAMC,OAAuBI,eAASR,EAAMG,2BAAMK,MAAM,CAChE,MAAMS,YAA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EACJ7G,SAASmF,cAAc,eAAe8B,oBAAgCA,SACtEE,EAAgBH,GAActH,MAAAA,SAAAA,EAASiH,MAAO,SAEhD,OAAO,IAAI6C,SAAQ,CAACC,EAASzE,KAC3B6B,EAAO9F,iBAAiB,QAAQ,KAC1BhB,OAAOwH,WACTxH,OAAOwH,UAAUoC,KAAKjK,GACtB+J,EAAQ1J,OAAOwH,YAEfvC,EAAO,IAAIhD,MAAM,8CAIrB6E,EAAO9F,iBAAiB,SAAS,KAC/BiE,EAAO,IAAIhD,MAAM,mGAcuC8F,IACzD/H,OAAOwH,UAGVxH,OAAOwH,UAAUsC,mBAAmB/B,GAFpCvE,QAAQpB,MAAM"}
1
+ {"version":3,"file":"airwallex.cjs.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport {\n getBrowserInfo as getBrowserInfoFn,\n getDeviceFingerprint as getDeviceFingerprintFn,\n get3dsReturnUrl as get3dsReturnUrlFn,\n handle3ds as handle3dsFn,\n} from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js`;\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\nexport const loadAirwallex: typeof loadAirwallexFn = (options) => {\n return Promise.resolve().then(() => {\n if (typeof window === 'undefined') {\n return null;\n }\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n });\n });\n });\n};\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n window.Airwallex.redirectToCheckout(props);\n }\n};\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\nexport const getBrowserInfo: typeof getBrowserInfoFn = (data) => {\n return window.Airwallex.getBrowserInfo(data);\n};\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport const get3dsReturnUrl: typeof get3dsReturnUrlFn = (data) => {\n return window.Airwallex.get3dsReturnUrl(data);\n};\n\nexport const handle3ds: typeof handle3dsFn = (data) => {\n return window.Airwallex.handle3ds(data);\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","headOrBody","head","body","Error","appendChild","async","data","window","Airwallex","confirmPaymentIntent","err","console","error","confirmPaymentIntentWithSavedCard","type","options","createPaymentConsent","client_secret","createPaymentMethod","destroyElement","get3dsReturnUrl","getBrowserInfo","getDeviceFingerprint","getElement","id","getPaymentIntent","handle3ds","init","Promise","resolve","then","querySelector","reject","addEventListener","props","redirectToCheckout"],"mappings":";oEAqBA,MAAMA,EAAW,CACfC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAYMC,EAAiBC,GAA8B,WAAWR,EAASQ,IAAQR,EAASC,OAE3FQ,EAAgB,iCAETC,EAAmBC,IAC9B,MAAMC,EAASC,SAASC,cAAc,UACtCF,EAAOG,IAAM,GAAGJ,IAAaF,IAE7B,MAAMO,EAAaH,SAASI,MAAQJ,SAASK,KAE7C,IAAKF,EACH,MAAM,IAAIG,MAAM,6FAKlB,OAFAH,EAAWI,YAAYR,GAEhBA,gCA4E0DS,MAAOC,IACxE,GAAKC,OAAOC,UAKV,OAAOD,OAAOC,UAAUC,qBAAqBH,GALxB,CACrB,MAAMI,EAAM,wDAEZ,MADAC,QAAQC,MAAMF,GACR,IAAIP,MAAMO,+CAMyEL,MAAOC,IAClG,GAAKC,OAAOC,UAKV,OAAOD,OAAOC,UAAUK,kCAAkCP,GALrC,CACrB,MAAMI,EAAM,qEAEZ,MADAC,QAAQC,MAAMF,GACR,IAAIP,MAAMO,2BAzCiC,CAACI,EAAMC,IACrDR,OAAOC,UAIHD,OAAOC,UAAUV,cAAcgB,EAAMC,IAH5CJ,QAAQC,MAAM,kDACP,mCAgEwDP,MAAOC,IACxE,GAAKC,OAAOC,UAKV,OAAOD,OAAOC,UAAUQ,qBAAqBV,GALxB,CACrB,MAAMI,EA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B,MAAM,mGAcuC+B,IACzD3B,OAAOC,UAGVD,OAAOC,UAAU2B,mBAAmBD,GAFpCvB,QAAQC,MAAM"}
@@ -1,4 +1,3 @@
1
- /* Airwallex Checkout Component Version [0.2.40] */
2
- const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},t={prod:"https://pci-api.airwallex.com",demo:"https://pci-api-demo.airwallex.com",staging:"https://pci-api-staging.airwallex.com",qa:"https://pci-api-qa.airwallex.com",preview:"https://pci-api-preview.airwallex.com",dev:"http://localhost:8080"};class n{constructor(e,t){var n,i;this.domElement=null,this.gatewayUrl=e,this.options=t,this.iframe=window.document.createElement("iframe"),this.iframe.setAttribute("frameborder","0"),this.iframe.setAttribute("allowtransparency","true"),this.iframe.setAttribute("importance","high"),this.iframe.setAttribute("scrolling","no"),this.iframe.setAttribute("allowpaymentrequest","true"),null===(n=this.iframe)||void 0===n||n.setAttribute("style","\n height: 0;\n width: 100%;\n display: block;\n "),i=e=>{var t,n,i;if(e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)){const t=new CustomEvent(null===(n=e.data)||void 0===n?void 0:n.code,{detail:{type:null===(i=e.data)||void 0===i?void 0:i.type},bubbles:!0,composed:!0});window.document.dispatchEvent(t)}},window.addEventListener("message",(e=>{window.ReactNativeWebView&&window.ReactNativeWebView.postMessage(JSON.stringify(e.data)),i(e)}))}addResizeListener(e){window.addEventListener("message",(t=>{var n,i,o,l;if(t.origin===this.gatewayUrl&&t.isTrusted&&"onResize"===(null===(n=t.data)||void 0===n?void 0:n.code)&&e===(null===(i=t.data)||void 0===i?void 0:i.type)){const e=null===(o=this.iframe)||void 0===o?void 0:o.style;e&&(e.height=`${null===(l=t.data)||void 0===l?void 0:l.height}px`)}}))}mount(e){if("string"!=typeof e)return(null==e?void 0:e.hasChildNodes())&&(e.innerHTML=""),this.iframe&&e.appendChild(this.iframe),this.domElement=e,e;{const t=window.document.getElementById(e);return(null==t?void 0:t.hasChildNodes())&&(t.innerHTML=""),this.iframe&&(null==t||t.appendChild(this.iframe)),t&&(this.domElement=t),t}}blur(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"blur"},this.gatewayUrl)}clear(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"clear"},this.gatewayUrl)}destroy(){var e;this.clear(),null===(e=this.iframe)||void 0===e||e.remove(),this.iframe=null}focus(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"focus"},this.gatewayUrl)}unmount(){var e;this.clear(),this.iframe&&(null===(e=this.domElement)||void 0===e||e.removeChild(this.iframe))}update(e){var t,n;this.options={...this.options,...e},null===(n=null===(t=this.iframe)||void 0===t?void 0:t.contentWindow)||void 0===n||n.postMessage({code:"update",options:e},this.gatewayUrl)}async confirm(){throw new Error("Confirm is not supported in ElementBase")}success(e){throw new Error(`Call success with ${e.id} is not supported in ElementBase`)}fail(e){throw new Error(`Call fail with ${e.code}: ${e.message} is not supported in ElementBase`)}}const i=["cardNumber","expiry","cvc","paymentRequestButton","card","wechat","qrcode","redirect","dropIn","fullFeaturedCard","threeDsFrictionless","threeDsChallenge"],o={},l={cardNumber:null,expiry:null,cvc:null,threeDsFrictionless:null,threeDsChallenge:null,paymentRequestButton:null,card:null,wechat:null,qrcode:null,redirect:null,dropIn:null,fullFeaturedCard:null},r=e=>{var t;return i.includes(e)?(null===(t=l[e])||void 0===t||t.destroy(),l[e]=null,!0):(console.warn(`destroyElement with type: ${e} not support!`),!1)},a=e=>i.includes(e)?l[e]:(console.warn(`getElement with type: ${e} not support!`),null),s=(e,t)=>i.includes(e)?(l[e]=t,!0):(console.warn(`destroyElement with type: ${e} not support!`),!1);class d extends n{constructor(e,t,n){var i,l,r,a;super(e,n),this.confirmResponse=t,null===(i=this.iframe)||void 0===i||i.setAttribute("src",`${e}/#/elements/3ds-frictionless?options=${encodeURIComponent(JSON.stringify(this.options))}&lang=${null===(l=o)||void 0===l?void 0:l.locale}`),null===(r=this.iframe)||void 0===r||r.setAttribute("name","Airwallex 3DS frictionless iframe"),null===(a=this.iframe)||void 0===a||a.setAttribute("title","Airwallex 3DS frictionless iframe"),window.addEventListener("message",(e=>{var t,n,i,o;e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)&&"threeDsFrictionless"===(null===(n=e.data)||void 0===n?void 0:n.type)&&(null===(o=null===(i=this.iframe)||void 0===i?void 0:i.contentWindow)||void 0===o||o.postMessage({code:"update",data:this.confirmResponse},this.gatewayUrl))}))}async confirm(){var e,t;return null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"confirm",data:this.confirmResponse},this.gatewayUrl),null}}class c extends n{constructor(e,t,n){var i,o,l,r,a,s,d,c,u;super(e,n),this.confirmResponse=t;const w=(null==n?void 0:n.customizeChallengeWindowSize)&&b[null==n?void 0:n.customizeChallengeWindowSize]?b[null==n?void 0:n.customizeChallengeWindowSize]:b["05"],h=(null===(i=null==n?void 0:n.style)||void 0===i?void 0:i.popupWidth)?`${null===(o=null==n?void 0:n.style)||void 0===o?void 0:o.popupWidth}px`:w[0],m=(null===(l=null==n?void 0:n.style)||void 0===l?void 0:l.popupHeight)?`${null===(r=null==n?void 0:n.style)||void 0===r?void 0:r.popupHeight}px`:w[1];null===(a=this.iframe)||void 0===a||a.setAttribute("src",`${e}/#/elements/3ds-challenge?options=${encodeURIComponent(JSON.stringify(this.options))}`),null===(s=this.iframe)||void 0===s||s.setAttribute("name","Airwallex 3DS challenge iframe"),null===(d=this.iframe)||void 0===d||d.setAttribute("title","Airwallex 3DS challenge iframe"),null===(c=this.iframe)||void 0===c||c.setAttribute("scrolling","yes"),null===(u=this.iframe)||void 0===u||u.setAttribute("style",`\n background: #fff;\n width: ${h};\n height: ${m};\n position: ${(null==n?void 0:n.useDefaultStyle)?"absolute":"relative"};\n top: ${(null==n?void 0:n.useDefaultStyle)?"50%":"0"};\n left: ${(null==n?void 0:n.useDefaultStyle)?"50%":"0"};\n transform: ${(null==n?void 0:n.useDefaultStyle)?"translate(-50%, -50%)":"none"};\n border-radius: ${(null==n?void 0:n.useDefaultStyle)?"4px":"0"};\n `),window.addEventListener("message",(e=>{var t,n,i,o;e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)&&"threeDsChallenge"===(null===(n=e.data)||void 0===n?void 0:n.type)&&(null===(o=null===(i=this.iframe)||void 0===i?void 0:i.contentWindow)||void 0===o||o.postMessage({code:"update",data:this.confirmResponse},this.gatewayUrl))}))}async confirm(){var e,t;return null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"confirm",data:this.confirmResponse},this.gatewayUrl),null}}let u,w,h,m,p,v;const g={resolver:null,reject:null,awaiting:!1},f=e=>{var t;null===(t=document.querySelector(`#${e}`))||void 0===t||t.remove(),r("threeDsFrictionless"===e?"threeDsFrictionless":"threeDsChallenge")},y=()=>{g.awaiting=!1,g.resolver=null,g.reject=null},x=e=>{var t,n,i;const o="data"in e?e.data:e.detail,l=["hpp","api"].includes(h),r=l?null:a(h),d=(null==r?void 0:r.gatewayUrl)||window.location.origin;("data"in e&&e.origin===d&&e.isTrusted||l)&&"threeDsFrictionless"===(null==o?void 0:o.type)&&(f("threeDsChallenge"),"onSuccess"===(null==o?void 0:o.code)&&(console.log("frictionlessHandler onSuccess",(new Date).toLocaleTimeString()),null===(t=g.resolver)||void 0===t||t.call(g,o),y(),f("threeDsFrictionless")),["onError","onChallengeError"].includes(null==o?void 0:o.code)&&(console.log(`frictionlessHandler ${null==o?void 0:o.code}`,(new Date).toLocaleTimeString()),null===(n=g.reject)||void 0===n||n.call(g,o),y(),f("threeDsFrictionless")),"onChallenge"===(null==o?void 0:o.code)&&(console.log("frictionlessHandler onChallenge threeDsFrictionlessType",(new Date).toLocaleTimeString()),f("threeDsFrictionless"),w?u=w:(u=document.createElement("div"),u.setAttribute("id","threeDsChallenge"),u.setAttribute("style","\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 0;\n z-index: 1500;\n overflow: hidden;\n background: rgba(0, 0, 0, 0.75);\n "),document.body.appendChild(u)),s("threeDsChallenge",new c(p,o,{origin:window.location.origin,style:{popupWidth:undefined,popupHeight:undefined},useDefaultStyle:null===w,customizeChallengeWindowSize:m,intent:v})),window.addEventListener("message",A),null===(i=a("threeDsChallenge"))||void 0===i||i.mount(u)))},A=e=>{var t,n;const i="data"in e?e.data:e.detail,o=["hpp","api"].includes(h),l=o?null:a(h),r=(null==l?void 0:l.gatewayUrl)||window.location.origin;("data"in e&&e.origin===r&&e.isTrusted||o)&&"threeDsChallenge"===(null==i?void 0:i.type)&&("onReady"===(null==i?void 0:i.code)&&(console.log("challengeHandler onReady",(new Date).toLocaleTimeString()),setTimeout((()=>{u.style.height="100%"}),2e3)),"onChallengeSuccess"===(null==i?void 0:i.code)&&(u.style.height="0"),"onSuccess"===(null==i?void 0:i.code)&&(console.log("challengeHandler onSuccess",(new Date).toLocaleTimeString()),null===(t=g.resolver)||void 0===t||t.call(g,i),y(),f("threeDsChallenge")),["onError","onChallengeError"].includes(null==i?void 0:i.code)&&(console.log(`challengeHandler ${null==i?void 0:i.code}`,(new Date).toLocaleTimeString()),null===(n=g.reject)||void 0===n||n.call(g,i),y(),f("threeDsChallenge")))},b={"01":["250px","400px"],"02":["390px","400px"],"03":["500px","600px"],"04":["600px","400px"],"05":["100%","100%"]},E=e=>{const{navigator:t,screen:n}=window||{},{language:i}=t||{},{colorDepth:o,height:l,width:r}=n||{},{intent_id:a,env:s}=e||{};let d;return e&&(d=D({intent_id:a,env:s})),{device_id:d,screen_height:l,screen_width:r,screen_color_depth:o,language:i,timezone:(new Date).getTimezoneOffset(),browser:{java_enabled:window.navigator.javaEnabled(),javascript_enabled:!0,user_agent:t.userAgent}}};let C="";const D=({intent_id:e="",env:t="prod"})=>{if(!C.includes(e)){const n="prod"===t?"9ozphlqx":"45ssiuz3",i=document.createElement("script");C=`${e}${Date.now()}`,i.src=`https://h.online-metrix.net/fp/tags.js?org_id=${n}&session_id=${C}`,document.body.appendChild(i)}return C},$=n=>{const{env:i,checkoutOrigin:o}=n;return`${t[i||"prod"]}/api/v1/checkout/elements/3ds?origin=https://${e[i||"prod"]}&checkoutOrigin=${o||window.location.origin}`},S=t=>{const{cardBin:n,next_action:i,authFormContainer:o,intent:l,challengeWindowSize:r,env:c}=t;return(({intent:e,gatewayUrl:t,cardBin:n,next_action:i,authFormContainer:o,componentType:l,challengeWindowSize:r})=>{var c;g.awaiting&&console.warn("Should wait previous 3ds flow finished before execute new one!"),console.log("threeDsHandler onChallenge type",(new Date).toLocaleTimeString()),w=document.getElementById(o||""),h=l,m=r,p=t,v=e,f("threeDsFrictionless"),s("threeDsFrictionless",new d(p,{code:"",type:"threeDsFrictionless",cardBin:n,next_action:i},{intent:v,origin:window.location.origin}));const u=document.createElement("div");return u.setAttribute("id","threeDsFrictionless"),document.body.appendChild(u),window.addEventListener("message",x),null===(c=a("threeDsFrictionless"))||void 0===c||c.mount(u),new Promise(((e,t)=>{g.resolver=e,g.reject=t,g.awaiting=!0}))})({gatewayUrl:`https://${e[c]}`,cardBin:n,intent:l,next_action:i,authFormContainer:o,componentType:"api",challengeWindowSize:r})},P=t=>`https://${e[t]||"checkout.airwallex.com"}`,F=`/assets/bundle.${[0,2,40].join(".")}.min.js`,T=e=>{const t=document.createElement("script");t.src=`${e}${F}`;const n=document.head||document.body;if(!n)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return n.appendChild(t),t},W=e=>Promise.resolve().then((()=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;const t=document.querySelector(`script[src="${F}"], script[src="${F}/"]`)||T(P((null==e?void 0:e.env)||"prod"));return new Promise(((n,i)=>{t.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),n(window.Airwallex)):i(new Error("Failed to load Airwallex on load event"))})),t.addEventListener("error",(()=>{i(new Error("Failed to load Airwallex scripts"))}))}))})),R=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},U=e=>{window.Airwallex?window.Airwallex.redirectToCheckout(e):console.error("Please loadAirwallex() before redirectToCheckout();")},z=(e,t)=>window.Airwallex?window.Airwallex.createElement(e,t):(console.error("Please loadAirwallex() before createElement();"),null),L=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),_=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),k=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},q=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},M=async(e,t)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,t);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},H=async(e,t)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,t);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},I=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}};export{k as confirmPaymentIntent,q as confirmPaymentIntentWithSavedCard,z as createElement,I as createPaymentConsent,M as createPaymentMethod,L as destroyElement,$ as get3dsReturnUrl,E as getBrowserInfo,D as getDeviceFingerprint,_ as getElement,P as getGatewayUrl,H as getPaymentIntent,S as handle3ds,R as init,W as loadAirwallex,T as loadAirwallexJs,U as redirectToCheckout};
3
- /* Airwallex @Charlie.Lang */
1
+ /* Airwallex Checkout Component Version [0.2.49] */
2
+ const e={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},r=r=>`https://${e[r]||e.prod}`,o="/assets/elements.bundle.min.js",l=e=>{const r=document.createElement("script");r.src=`${e}${o}`;const l=document.head||document.body;if(!l)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return l.appendChild(r),r},n=e=>Promise.resolve().then((()=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;const n=document.querySelector(`script[src="${o}"], script[src="${o}/"]`)||l(r((null==e?void 0:e.env)||"prod"));return new Promise(((r,o)=>{n.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),r(window.Airwallex)):o(new Error("Failed to load Airwallex on load event"))})),n.addEventListener("error",(()=>{o(new Error("Failed to load Airwallex scripts"))}))}))})),i=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},w=e=>{window.Airwallex?window.Airwallex.redirectToCheckout(e):console.error("Please loadAirwallex() before redirectToCheckout();")},t=(e,r)=>window.Airwallex?window.Airwallex.createElement(e,r):(console.error("Please loadAirwallex() before createElement();"),null),a=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),d=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),c=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},s=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},x=async(e,r)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,r);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},A=async(e,r)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,r);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},m=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},u=e=>window.Airwallex.getBrowserInfo(e),f=e=>window.Airwallex.getDeviceFingerprint(e),h=e=>window.Airwallex.get3dsReturnUrl(e),y=e=>window.Airwallex.handle3ds(e);export{c as confirmPaymentIntent,s as confirmPaymentIntentWithSavedCard,t as createElement,m as createPaymentConsent,x as createPaymentMethod,a as destroyElement,h as get3dsReturnUrl,u as getBrowserInfo,f as getDeviceFingerprint,d as getElement,r as getGatewayUrl,A as getPaymentIntent,y as handle3ds,i as init,n as loadAirwallex,l as loadAirwallexJs,w as redirectToCheckout};
4
3
  //# sourceMappingURL=airwallex.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"airwallex.es.js","sources":["../../src/util.ts","../../src/element.ts","../../src/airwallex.ts","../../src/threeDsFrictionless.ts","../../src/threeDsChallenge.ts","../../src/handle3dsFlow.ts","../../src/fraud.ts","../../src/npmPackage/index.ts"],"sourcesContent":["export const simulateFormSubmit = (data: { [k: string]: string }, action: string): void => {\n const formEle = document.createElement('form');\n formEle.setAttribute('method', 'post');\n formEle.setAttribute('style', 'height: 0; overflow: hidden;');\n formEle.action = action;\n Object.keys(data || {}).forEach((key: string) => {\n const inputEle = document.createElement('input');\n inputEle.type = 'hidden';\n inputEle.name = key;\n inputEle.value = data[key];\n formEle.appendChild(inputEle);\n });\n const submitBtn = document.createElement('input');\n submitBtn.type = 'submit';\n formEle.appendChild(submitBtn);\n document.body.appendChild(formEle);\n submitBtn.click();\n};\n\ntype eventHandlerType = (event: MessageEvent) => void;\n\nexport const useMessageListener = (eventHandler: eventHandlerType): void => {\n window.addEventListener('message', (event: MessageEvent) => {\n if (window.ReactNativeWebView) {\n window.ReactNativeWebView.postMessage(JSON.stringify(event.data));\n }\n\n eventHandler(event);\n });\n};\n\nexport const ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\nexport const ENV_CHECKOUT_SERVER_HOST = {\n prod: 'https://pci-api.airwallex.com',\n demo: 'https://pci-api-demo.airwallex.com',\n staging: 'https://pci-api-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'https://pci-api-qa.airwallex.com',\n preview: 'https://pci-api-preview.airwallex.com',\n dev: 'http://localhost:8080',\n};\n","import { Element, ElementError } from '../types/element';\nimport { useMessageListener } from './util';\nimport { Intent } from '../types/cardNumber';\n\nexport class ElementBase implements Element {\n gatewayUrl: string;\n options?: Element['options'];\n iframe: HTMLIFrameElement | null;\n domElement: null | HTMLElement;\n\n constructor(gatewayUrl: string, options?: Element['options']) {\n this.domElement = null;\n this.gatewayUrl = gatewayUrl;\n this.options = options;\n this.iframe = window.document.createElement('iframe');\n this.iframe.setAttribute('frameborder', '0');\n this.iframe.setAttribute('allowtransparency', 'true');\n this.iframe.setAttribute('importance', 'high');\n this.iframe.setAttribute('scrolling', 'no');\n this.iframe.setAttribute('allowpaymentrequest', 'true');\n this.iframe?.setAttribute(\n 'style',\n `\n height: 0;\n width: 100%;\n display: block;\n `,\n );\n useMessageListener((event: MessageEvent) => {\n // exist for the old user, already handle onReady event in individual Element\n if (event.origin === this.gatewayUrl && event.isTrusted && event.data?.code === 'onReady') {\n const customEvent = new CustomEvent(event.data?.code, {\n detail: {\n type: event.data?.type,\n },\n bubbles: true,\n composed: true,\n });\n window.document.dispatchEvent(customEvent);\n }\n });\n }\n\n addResizeListener(type: string): void {\n window.addEventListener('message', (event: MessageEvent) => {\n if (event.origin === this.gatewayUrl && event.isTrusted) {\n if (event.data?.code === 'onResize' && type === event.data?.type) {\n const styleAttribute = this.iframe?.style;\n if (styleAttribute) {\n styleAttribute.height = `${event.data?.height}px`;\n }\n }\n }\n });\n }\n\n mount(domElement: string | HTMLElement): null | HTMLElement {\n if (typeof domElement !== 'string') {\n if (domElement?.hasChildNodes()) {\n domElement.innerHTML = '';\n }\n this.iframe && domElement.appendChild(this.iframe);\n this.domElement = domElement;\n return domElement;\n } else {\n const getDomElement = window.document.getElementById(domElement);\n if (getDomElement?.hasChildNodes()) {\n getDomElement.innerHTML = '';\n }\n this.iframe && getDomElement?.appendChild(this.iframe);\n if (getDomElement) {\n this.domElement = getDomElement;\n }\n return getDomElement;\n }\n }\n\n blur(): void {\n this.iframe?.contentWindow?.postMessage({ code: 'blur' }, this.gatewayUrl);\n }\n\n clear(): void {\n this.iframe?.contentWindow?.postMessage({ code: 'clear' }, this.gatewayUrl);\n }\n\n destroy(): void {\n this.clear();\n this.iframe?.remove();\n this.iframe = null;\n }\n\n focus(): void {\n this.iframe?.contentWindow?.postMessage({ code: 'focus' }, this.gatewayUrl);\n }\n\n unmount(): void {\n this.clear();\n this.iframe && this.domElement?.removeChild(this.iframe);\n }\n\n update(options?: Element['options']): void {\n this.options = { ...this.options, ...options };\n this.iframe?.contentWindow?.postMessage({ code: 'update', options }, this.gatewayUrl);\n }\n async confirm(): Promise<Intent | null> {\n throw new Error('Confirm is not supported in ElementBase');\n }\n success(value: Intent): void {\n throw new Error(`Call success with ${value.id} is not supported in ElementBase`);\n }\n fail(error: ElementError): void {\n throw new Error(`Call fail with ${error.code}: ${error.message} is not supported in ElementBase`);\n }\n}\n","import { ElementBase } from './element';\nimport { ElementType } from '../types/element';\nimport { CardNumberElement } from './cardNumber';\nimport { ExpiryElement } from './expiry';\nimport { CvcElement } from './cvc';\nimport { PaymentRequestButtonElement } from './paymentRequestButton';\nimport { DropInElement } from './dropIn';\nimport { FullFeaturedCardElement } from './fullFeaturedCard';\nimport { CardElement } from './card';\nimport { WechatElement } from './wechat';\nimport { QrcodeElement } from './qrcode';\nimport { RedirectElement } from './redirect';\nimport { processQueryParams } from './processParams';\nimport { getGatewayUrl } from './npmPackage';\n\nimport {\n InitOptions,\n HostPaymentPage,\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n} from '../types/airwallex';\n\nimport { FullFeaturedCardElementOptions } from '../types/element';\nimport { RedirectElementOptions } from '../types/redirectElement';\nimport { DropInElementOptions } from '../types/dropInElement';\n\nexport const ElementList = [\n 'cardNumber',\n 'expiry',\n 'cvc',\n 'paymentRequestButton',\n 'card',\n 'wechat',\n 'qrcode',\n 'redirect',\n 'dropIn',\n 'fullFeaturedCard',\n];\n\nexport const ThreeDsElementList = <const>['threeDsFrictionless', 'threeDsChallenge'];\nexport type ExtendElementType = ElementType | typeof ThreeDsElementList[number];\nexport const ExtentElementList = [...ElementList, ...ThreeDsElementList];\n\nexport interface Config {\n gatewayUrl: string;\n options?: InitOptions;\n}\n\nexport interface Elements {\n cardNumber: ElementBase | null;\n expiry: ElementBase | null;\n cvc: ElementBase | null;\n threeDsFrictionless: ElementBase | null;\n threeDsChallenge: ElementBase | null;\n paymentRequestButton: ElementBase | null;\n card: ElementBase | null;\n wechat: ElementBase | null;\n qrcode: ElementBase | null;\n redirect: ElementBase | null;\n dropIn: ElementBase | null;\n fullFeaturedCard: ElementBase | null;\n}\n\nexport const CONFIG: Config = {\n gatewayUrl: '',\n options: {} as InitOptions,\n};\n\nexport const ELEMENTS: Elements = {\n cardNumber: null,\n expiry: null,\n cvc: null,\n threeDsFrictionless: null,\n threeDsChallenge: null,\n paymentRequestButton: null,\n card: null,\n wechat: null,\n qrcode: null,\n redirect: null,\n dropIn: null,\n fullFeaturedCard: null,\n};\n\nexport const init: typeof initFn = (options) => {\n if (options?.env || !CONFIG.gatewayUrl) {\n CONFIG.gatewayUrl = getGatewayUrl(options?.env || 'prod');\n }\n CONFIG.options = options;\n};\n\nexport type Key = Exclude<keyof HostPaymentPage, 'id' | 'intent_id' | 'host'>;\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n const { env, ...restProps } = props;\n const parameters = processQueryParams(restProps);\n const { id, ...rest } = parameters || {};\n const queryParamsKeys = Object.keys(rest) as Key[];\n const paramsArray: string[] = [];\n queryParamsKeys.forEach((key: Key) => {\n paramsArray.push(`${key}=${rest[key]}`);\n });\n const redirectUrl =\n props.mode === 'recurring'\n ? `${getGatewayUrl(env || 'prod')}/#/standalone/recurring?${paramsArray.join('&')}`\n : `${getGatewayUrl(env || 'prod')}/#/standalone/checkout/${id || rest?.intent_id}?${paramsArray.join('&')}`;\n window.location.href = redirectUrl;\n};\n\nexport const createElement: typeof createElementFn = (type, options) => {\n const newOptions = options ?? { origin: '' };\n if (!newOptions.origin) {\n newOptions.origin = CONFIG.options?.origin;\n }\n if (!ElementList.includes(type)) {\n console.warn(`createElement with type: ${type} not support!`);\n return null;\n }\n if (type === 'cardNumber') {\n ELEMENTS[type] = new CardNumberElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'card') {\n ELEMENTS[type] = new CardElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'fullFeaturedCard') {\n ELEMENTS[type] = new FullFeaturedCardElement(CONFIG.gatewayUrl, newOptions as FullFeaturedCardElementOptions);\n return ELEMENTS[type];\n } else if (type === 'wechat') {\n ELEMENTS[type] = new WechatElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'qrcode') {\n ELEMENTS[type] = new QrcodeElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'redirect') {\n ELEMENTS[type] = new RedirectElement(CONFIG.gatewayUrl, newOptions as RedirectElementOptions);\n return ELEMENTS[type];\n } else if (type === 'paymentRequestButton') {\n ELEMENTS[type] = new PaymentRequestButtonElement(CONFIG.gatewayUrl, newOptions);\n return ELEMENTS[type];\n } else if (type === 'dropIn') {\n ELEMENTS[type] = new DropInElement(CONFIG.gatewayUrl, (newOptions as unknown) as DropInElementOptions);\n return ELEMENTS[type];\n } else if (type === 'expiry' || type === 'cvc') {\n ELEMENTS[type] =\n type === 'expiry'\n ? new ExpiryElement(CONFIG.gatewayUrl, newOptions)\n : new CvcElement(CONFIG.gatewayUrl, newOptions);\n\n window.addEventListener('message', (event: MessageEvent) => {\n // Communicate cvc and expiry to cardNumber element\n if (\n event.origin === CONFIG.gatewayUrl &&\n event.isTrusted &&\n type === event.data?.type &&\n event.data?.code === 'onChange'\n ) {\n ELEMENTS.cardNumber?.iframe?.contentWindow?.postMessage(\n { code: `update_${event.data?.type}`, data: event.data },\n CONFIG.gatewayUrl,\n );\n }\n });\n return ELEMENTS[type];\n }\n\n return null;\n};\n\nexport const destroyElement = (type: ExtendElementType): boolean => {\n if (ExtentElementList.includes(type)) {\n ELEMENTS[type]?.destroy();\n ELEMENTS[type] = null;\n return true;\n } else {\n console.warn(`destroyElement with type: ${type} not support!`);\n return false;\n }\n};\n\nexport const getElement = (type: ExtendElementType): ElementBase | null => {\n if (ExtentElementList.includes(type)) {\n return ELEMENTS[type];\n } else {\n console.warn(`getElement with type: ${type} not support!`);\n return null;\n }\n};\n\nexport const setElement = (type: ExtendElementType, element: ElementBase): boolean => {\n if (ExtentElementList.includes(type)) {\n ELEMENTS[type] = element;\n return true;\n } else {\n console.warn(`destroyElement with type: ${type} not support!`);\n return false;\n }\n};\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n console.info(`Confirm intent ${data?.intent_id || data?.id} with client secret: ${data?.client_secret}`);\n if (data?.element) {\n return (data?.element as CardNumberElement).confirm(data);\n } else {\n console.warn('Card number element must be provided for card payment confirm!');\n return false;\n }\n};\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n console.info(`Confirm intent ${data?.intent_id || data?.id} with client secret: ${data?.client_secret}`);\n if (data?.element && data?.methodId) {\n return (data?.element as CvcElement).confirm(data);\n } else {\n console.warn('Payment method id must be provided for cvc payment confirm!');\n return false;\n }\n};\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n console.info(`Create payment method with client secret: ${client_secret}`);\n if (data?.element) {\n return (data?.element as CardNumberElement).createPaymentMethod({\n ...data,\n client_secret,\n });\n } else {\n console.warn('Either payment method id or element must be provided for payment method create!');\n return false;\n }\n};\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n console.info(`Create payment consent with client secret: ${data.client_secret}`);\n if (data?.element) {\n return (data?.element as CardElement).createPaymentConsent(data);\n } else {\n console.warn('Either payment method id or element must be provided for create payment consent!');\n return false;\n }\n};\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n return (ELEMENTS.cardNumber as CardNumberElement)?.getPaymentIntent(id, client_secret) || false;\n};\n","import { ElementBase } from './element';\nimport { ElementOptions, ExtendEventDetail } from '../types/element';\nimport { Intent } from '../types/cardNumber';\nimport { CONFIG } from './airwallex';\n\nexport class ThreeDsFrictionlessElement extends ElementBase {\n confirmResponse: ExtendEventDetail;\n\n constructor(gatewayUrl: string, confirmResponse: ExtendEventDetail, options?: ElementOptions & { intent: Intent }) {\n super(gatewayUrl, options);\n this.confirmResponse = confirmResponse;\n this.iframe?.setAttribute(\n 'src',\n `${gatewayUrl}/#/elements/3ds-frictionless?options=${encodeURIComponent(JSON.stringify(this.options))}&lang=${\n CONFIG.options?.locale\n }`,\n );\n this.iframe?.setAttribute('name', 'Airwallex 3DS frictionless iframe');\n this.iframe?.setAttribute('title', 'Airwallex 3DS frictionless iframe');\n window.addEventListener('message', (event: MessageEvent) => {\n if (\n event.origin === this.gatewayUrl &&\n event.isTrusted &&\n event.data?.code === 'onReady' &&\n event.data?.type === 'threeDsFrictionless'\n ) {\n this.iframe?.contentWindow?.postMessage({ code: 'update', data: this.confirmResponse }, this.gatewayUrl);\n }\n });\n }\n async confirm(): Promise<Intent | null> {\n this.iframe?.contentWindow?.postMessage(\n {\n code: 'confirm',\n data: this.confirmResponse,\n },\n this.gatewayUrl,\n );\n return null;\n }\n}\n","import { ElementBase } from './element';\nimport { ElementOptions, ExtendEventDetail } from '../types/element';\nimport { Intent } from '../types/cardNumber';\nimport { CHALLENGE_WINDOW_SIZE_MAP } from './fraud';\n\nexport class ThreeDsChallengeElement extends ElementBase {\n confirmResponse: ExtendEventDetail;\n\n constructor(\n gatewayUrl: string,\n confirmResponse: ExtendEventDetail,\n options?: ElementOptions & { useDefaultStyle: boolean; customizeChallengeWindowSize?: string; intent: Intent },\n ) {\n super(gatewayUrl, options);\n this.confirmResponse = confirmResponse;\n // If provided predefined challenge window size, then use it, otherwise use '05' which is ['100%', '100%']\n const challengeWindowSize =\n options?.customizeChallengeWindowSize && CHALLENGE_WINDOW_SIZE_MAP[options?.customizeChallengeWindowSize]\n ? CHALLENGE_WINDOW_SIZE_MAP[options?.customizeChallengeWindowSize]\n : CHALLENGE_WINDOW_SIZE_MAP['05'];\n // if merchant provided the popupWidth when build element, then use it, otherwise use the width of challengeWindowSize\n const authPopupWidth = options?.style?.popupWidth ? `${options?.style?.popupWidth}px` : challengeWindowSize[0];\n // if merchant provided the popupHeight when build element, then use it, otherwise use the height of challengeWindowSize\n const authPopupHeight = options?.style?.popupHeight ? `${options?.style?.popupHeight}px` : challengeWindowSize[1];\n this.iframe?.setAttribute(\n 'src',\n `${gatewayUrl}/#/elements/3ds-challenge?options=${encodeURIComponent(JSON.stringify(this.options))}`,\n );\n this.iframe?.setAttribute('name', 'Airwallex 3DS challenge iframe');\n this.iframe?.setAttribute('title', 'Airwallex 3DS challenge iframe');\n this.iframe?.setAttribute('scrolling', 'yes');\n this.iframe?.setAttribute(\n 'style',\n `\n background: #fff;\n width: ${authPopupWidth};\n height: ${authPopupHeight};\n position: ${options?.useDefaultStyle ? 'absolute' : 'relative'};\n top: ${options?.useDefaultStyle ? '50%' : '0'};\n left: ${options?.useDefaultStyle ? '50%' : '0'};\n transform: ${options?.useDefaultStyle ? 'translate(-50%, -50%)' : 'none'};\n border-radius: ${options?.useDefaultStyle ? '4px' : '0'};\n `,\n );\n window.addEventListener('message', (event: MessageEvent) => {\n if (\n event.origin === this.gatewayUrl &&\n event.isTrusted &&\n event.data?.code === 'onReady' &&\n event.data?.type === 'threeDsChallenge'\n ) {\n this.iframe?.contentWindow?.postMessage({ code: 'update', data: this.confirmResponse }, this.gatewayUrl);\n }\n });\n }\n async confirm(): Promise<Intent | null> {\n this.iframe?.contentWindow?.postMessage(\n {\n code: 'confirm',\n data: this.confirmResponse,\n },\n this.gatewayUrl,\n );\n return null;\n }\n}\n","import { ThreeDsFrictionlessElement } from './threeDsFrictionless';\nimport { ThreeDsChallengeElement } from './threeDsChallenge';\nimport { destroyElement, setElement, getElement } from './airwallex';\nimport { ElementType, EventCode, ElementError, ExtendEventDetail } from '../types/element';\nimport { NextAction } from '../types/fraud';\nimport { Intent } from '../types/cardNumber';\n\ntype Resolver = (value: ExtendEventDetail | PromiseLike<ExtendEventDetail>) => void;\ntype Reject = (error?: ElementError) => void;\n\ntype ThreeDsPromiseType = {\n resolver: Resolver | null;\n reject: Reject | null;\n awaiting: boolean;\n};\n\nconst threeDsFrictionlessType = 'threeDsFrictionless';\nconst threeDsChallengeType = 'threeDsChallenge';\n/**\n * These variables are used in element iframe, frictionless iframe and challenge iframe\n * Different iframe communicate with events, so use the global variable instead of inject the events.\n */\n// The div container that contains the iframe if merchant not provided\nlet challengeDiv: HTMLElement;\n// The error handler for 3ds result\nlet customizeAuthFormContainer: HTMLElement | null;\n// The container that contains the iframe which is provided by merchant\nlet type: ExtendElementType | 'hpp' | 'api';\n// The customize popup width provided by merchant when mount element\nlet customizePopupWidth: number | undefined;\n// The customize popup height provided by merchant when mount element\nlet customizePopupHeight: number | undefined;\n// The customize challenge window size by merchant when handle 3ds\nlet customizeChallengeWindowSize: string | undefined;\n// The gateway url of the gateway url for build iframe\nlet customizeGatewayUrl: string;\n// The intent that you would like to confirm\nlet intentData: Intent;\n// The resolver for 3ds flow result\nconst threeDsPromise: ThreeDsPromiseType = {\n resolver: null,\n reject: null,\n awaiting: false,\n};\n\nconst ThreeDsElementList = ['threeDsFrictionless', 'threeDsChallenge'] as const;\nexport type ExtendElementType = ElementType | typeof ThreeDsElementList[number];\nconst ExtendEventList = [\n 'onResize',\n 'onRedirect',\n 'onComplete',\n 'onChallenge',\n 'onChallengeSuccess',\n 'onChallengeError',\n 'onIntentRetrieved',\n 'onIntentRetrievedError',\n 'onPaymentMethodCreated',\n 'onPaymentMethodCreatedError',\n] as const;\nexport type ExtendEventCode = EventCode | typeof ExtendEventList[number];\n\n// Clear the 3DS iframe\nexport const clear3Ds = (type: typeof threeDsFrictionlessType | typeof threeDsChallengeType): void => {\n document.querySelector(`#${type}`)?.remove();\n if (type === threeDsFrictionlessType) {\n destroyElement(threeDsFrictionlessType);\n } else {\n destroyElement(threeDsChallengeType);\n }\n};\n\n// Clear 3ds Promis\nexport const clearThreeDsPromise = (): void => {\n threeDsPromise.awaiting = false;\n threeDsPromise.resolver = null;\n threeDsPromise.reject = null;\n};\n\n// HPP handle 3ds success\nexport const onHppSuccess = (value: ExtendEventDetail | undefined): void => {\n const customEvent = new CustomEvent('on3dsSuccess', {\n detail: value,\n bubbles: true,\n composed: true,\n });\n window.document.dispatchEvent(customEvent);\n};\n\n// HPP handle 3ds error\nexport const onHppError = (error?: ElementError): void => {\n const customEvent = new CustomEvent('on3dsError', {\n detail: {\n error,\n },\n bubbles: true,\n composed: true,\n });\n window.document.dispatchEvent(customEvent);\n};\n\ninterface ThreeDsHandlerProps {\n intent: Intent;\n gatewayUrl: string;\n cardBin: string;\n next_action: NextAction;\n authFormContainer?: string;\n componentType: ExtendElementType | 'hpp' | 'api';\n challengeWindowSize?: string;\n}\n\n/**\n * Both the handle3ds function(for api integration) and threeDsListener(for elements integration) would go through this function\n * @return {Promise<ExtendEventDetail>} Promise type which will resolve ExtendEventDetail type when success\n */\nexport const threeDsHandler = ({\n intent,\n gatewayUrl,\n cardBin,\n next_action,\n authFormContainer,\n componentType,\n challengeWindowSize,\n}: ThreeDsHandlerProps): Promise<ExtendEventDetail> => {\n if (threeDsPromise.awaiting) {\n console.warn('Should wait previous 3ds flow finished before execute new one!');\n }\n console.log('threeDsHandler onChallenge type', new Date().toLocaleTimeString());\n customizeAuthFormContainer = document.getElementById(authFormContainer || '');\n type = componentType;\n customizeChallengeWindowSize = challengeWindowSize;\n customizeGatewayUrl = gatewayUrl;\n intentData = intent;\n\n clear3Ds(threeDsFrictionlessType);\n setElement(\n threeDsFrictionlessType,\n new ThreeDsFrictionlessElement(\n customizeGatewayUrl,\n {\n code: '',\n type: threeDsFrictionlessType,\n cardBin,\n next_action,\n },\n {\n intent: intentData,\n origin: window.location.origin,\n },\n ),\n );\n const frictionlessDiv = document.createElement('div');\n frictionlessDiv.setAttribute('id', threeDsFrictionlessType);\n document.body.appendChild(frictionlessDiv);\n window.addEventListener('message', frictionlessHandler);\n getElement(threeDsFrictionlessType)?.mount(frictionlessDiv);\n\n return new Promise((resolve: Resolver, reject: Reject) => {\n threeDsPromise.resolver = resolve;\n threeDsPromise.reject = reject;\n threeDsPromise.awaiting = true;\n });\n};\n\n/**\n * Setup the frictionless iframe listeners\n * @param {CustomEvent | MessageEvent} event the event received from the frictionless iframe\n */\nconst frictionlessHandler = (event: CustomEvent | MessageEvent) => {\n const eventData = 'data' in event ? event.data : event.detail;\n const isHppOrApi = ['hpp', 'api'].includes(type);\n const element = isHppOrApi ? null : getElement(type as ExtendElementType);\n const gatewayUrl = element?.gatewayUrl || window.location.origin;\n const eventIsTrusted = ('data' in event && event.origin === gatewayUrl && event.isTrusted) || isHppOrApi;\n\n if (eventIsTrusted && eventData?.type === threeDsFrictionlessType) {\n clear3Ds(threeDsChallengeType);\n if (eventData?.code === 'onSuccess') {\n console.log('frictionlessHandler onSuccess', new Date().toLocaleTimeString());\n threeDsPromise.resolver?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsFrictionlessType);\n }\n if (['onError', 'onChallengeError'].includes(eventData?.code)) {\n console.log(`frictionlessHandler ${eventData?.code}`, new Date().toLocaleTimeString());\n threeDsPromise.reject?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsFrictionlessType);\n }\n if (eventData?.code === 'onChallenge') {\n console.log('frictionlessHandler onChallenge threeDsFrictionlessType', new Date().toLocaleTimeString());\n clear3Ds(threeDsFrictionlessType);\n if (!customizeAuthFormContainer) {\n challengeDiv = document.createElement('div');\n challengeDiv.setAttribute('id', threeDsChallengeType);\n challengeDiv.setAttribute(\n 'style',\n `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 0;\n z-index: 1500;\n overflow: hidden;\n background: rgba(0, 0, 0, 0.75);\n `,\n );\n document.body.appendChild(challengeDiv);\n } else {\n challengeDiv = customizeAuthFormContainer;\n }\n setElement(\n threeDsChallengeType,\n new ThreeDsChallengeElement(customizeGatewayUrl, eventData as ExtendEventDetail, {\n origin: window.location.origin,\n style: {\n popupWidth: customizePopupWidth,\n popupHeight: customizePopupHeight,\n },\n useDefaultStyle: customizeAuthFormContainer === null,\n customizeChallengeWindowSize,\n intent: intentData,\n }),\n );\n window.addEventListener('message', challengeHandler);\n getElement(threeDsChallengeType)?.mount(challengeDiv);\n }\n }\n};\n\n/**\n * Setup the challenge iframe listeners\n * @param {CustomEvent | MessageEvent} event the event received from the challenge iframe\n */\nconst challengeHandler = (event: CustomEvent | MessageEvent) => {\n const eventData = 'data' in event ? event.data : event.detail;\n const isHppOrApi = ['hpp', 'api'].includes(type);\n const element = isHppOrApi ? null : getElement(type as ExtendElementType);\n const gatewayUrl = element?.gatewayUrl || window.location.origin;\n const eventIsTrusted = ('data' in event && event.origin === gatewayUrl && event.isTrusted) || isHppOrApi;\n\n if (eventIsTrusted && eventData?.type === threeDsChallengeType) {\n if (eventData?.code === 'onReady') {\n console.log('challengeHandler onReady', new Date().toLocaleTimeString());\n setTimeout(() => {\n challengeDiv.style.height = '100%';\n }, 2000);\n }\n if (eventData?.code === 'onChallengeSuccess') {\n challengeDiv.style.height = '0';\n }\n if (eventData?.code === 'onSuccess') {\n console.log('challengeHandler onSuccess', new Date().toLocaleTimeString());\n threeDsPromise.resolver?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsChallengeType);\n }\n if (['onError', 'onChallengeError'].includes(eventData?.code)) {\n console.log(`challengeHandler ${eventData?.code}`, new Date().toLocaleTimeString());\n threeDsPromise.reject?.(eventData);\n clearThreeDsPromise();\n clear3Ds(threeDsChallengeType);\n }\n }\n};\n\ninterface Handle3dsFlowProps {\n type: ElementType | 'hpp';\n popupWidth?: number;\n popupHeight?: number;\n authFormContainer?: string;\n}\n\nexport const handle3dsFlow = ({ type, popupWidth, popupHeight, authFormContainer }: Handle3dsFlowProps): void => {\n customizePopupWidth = popupWidth;\n customizePopupHeight = popupHeight;\n\n /**\n * This function will listener to the message event from elements including HPP\n * @param {CustomEvent | MessageEvent} event add listener to handle event from elements\n */\n const threeDsListener = async (event: CustomEvent | MessageEvent) => {\n const eventData = 'data' in event ? event.data : event.detail;\n const isHpp = type === 'hpp';\n const element = isHpp ? null : getElement(type as ExtendElementType);\n const gatewayUrl = element?.gatewayUrl || window.location.origin;\n const eventIsTrusted = ('data' in event && event.origin === gatewayUrl && event.isTrusted) || isHpp;\n\n if (eventIsTrusted && eventData?.type === type && eventData?.code === 'onChallenge') {\n const { cardBin, next_action, intent } = eventData;\n try {\n const confirmResult = await threeDsHandler({\n gatewayUrl,\n cardBin,\n intent,\n next_action,\n authFormContainer,\n componentType: type,\n });\n\n if (type === 'hpp') {\n onHppSuccess(confirmResult);\n } else {\n if (confirmResult?.intent) {\n element?.success(confirmResult?.intent);\n }\n element?.iframe?.contentWindow?.postMessage({ code: 'on3dsSuccess', confirmResult }, gatewayUrl);\n }\n\n window.removeEventListener('message', threeDsListener);\n window.removeEventListener('message', frictionlessHandler);\n window.removeEventListener('message', challengeHandler);\n } catch (error) {\n if (type === 'hpp') {\n onHppError(error);\n } else {\n error && element?.fail(error);\n element?.iframe?.contentWindow?.postMessage({ code: 'on3dsError', error }, gatewayUrl);\n }\n\n window.removeEventListener('message', challengeHandler);\n }\n }\n };\n\n window.addEventListener('message', threeDsListener);\n};\n","import {\n Handle3dsRequest,\n Get3dsReturnUrlRequest,\n getBrowserInfo as getBrowserInfoFn,\n getDeviceFingerprint as getDeviceFingerprintFn,\n handle3ds as handle3dsFn,\n get3dsReturnUrl as get3dsReturnUrlFn,\n} from '../types/fraud';\nimport { threeDsHandler } from './handle3dsFlow';\nimport { ENV_HOST, ENV_CHECKOUT_SERVER_HOST } from './util';\n\nexport const CHALLENGE_WINDOW_SIZE_MAP: { [key: string]: [string, string] } = {\n '01': ['250px', '400px'],\n '02': ['390px', '400px'],\n '03': ['500px', '600px'],\n '04': ['600px', '400px'],\n '05': ['100%', '100%'],\n};\n\nexport const getBrowserInfo: typeof getBrowserInfoFn = (fingerprintRequest) => {\n const { navigator, screen } = window || {};\n const { language } = navigator || {};\n const { colorDepth, height, width } = screen || {};\n const { intent_id, env } = fingerprintRequest || {};\n let device_id;\n if (fingerprintRequest) {\n device_id = getDeviceFingerprint({ intent_id, env });\n }\n\n return {\n device_id,\n screen_height: height,\n screen_width: width,\n screen_color_depth: colorDepth,\n language: language,\n timezone: new Date().getTimezoneOffset(),\n browser: {\n java_enabled: window.navigator.javaEnabled(),\n javascript_enabled: true,\n user_agent: navigator.userAgent,\n },\n };\n};\n\nlet fraudSessionId = '';\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = ({ intent_id = '', env = 'prod' }) => {\n if (!fraudSessionId.includes(intent_id)) {\n const ORG_ID = env === 'prod' ? '9ozphlqx' : '45ssiuz3';\n const script = document.createElement('script');\n fraudSessionId = `${intent_id}${Date.now()}`;\n script.src = `https://h.online-metrix.net/fp/tags.js?org_id=${ORG_ID}&session_id=${fraudSessionId}`;\n document.body.appendChild(script);\n }\n\n return fraudSessionId;\n};\n\nexport const get3dsReturnUrl: typeof get3dsReturnUrlFn = (props: Get3dsReturnUrlRequest) => {\n const { env, checkoutOrigin } = props;\n return `${ENV_CHECKOUT_SERVER_HOST[env || 'prod']}/api/v1/checkout/elements/3ds?origin=https://${\n ENV_HOST[env || 'prod']\n }&checkoutOrigin=${checkoutOrigin || window.location.origin}`;\n};\n\nexport const handle3ds: typeof handle3dsFn = (props: Handle3dsRequest) => {\n const { cardBin, next_action, authFormContainer, intent, challengeWindowSize, env } = props;\n return threeDsHandler({\n gatewayUrl: `https://${ENV_HOST[env]}`,\n cardBin,\n intent,\n next_action,\n authFormContainer,\n componentType: 'api',\n challengeWindowSize,\n });\n};\n","import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../../types/airwallex';\nexport { getBrowserInfo, getDeviceFingerprint, get3dsReturnUrl, handle3ds } from '../../src/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../../types/index';\nimport { ENV_HOST } from '../util';\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || 'checkout.airwallex.com'}`;\n\nconst version = [process.env.version_major, process.env.version_minor, process.env.version_patch].join('.');\n\nconst STATIC_JS_URL = `/assets/bundle.${version}.min.js`;\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\nexport const loadAirwallex: typeof loadAirwallexFn = (options) => {\n return Promise.resolve().then(() => {\n if (typeof window === 'undefined') {\n return null;\n }\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n });\n });\n });\n};\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n window.Airwallex.redirectToCheckout(props);\n }\n};\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","ENV_CHECKOUT_SERVER_HOST","ElementBase","[object Object]","gatewayUrl","options","eventHandler","this","domElement","iframe","window","document","createElement","setAttribute","event","origin","isTrusted","data","code","customEvent","CustomEvent","detail","type","bubbles","composed","dispatchEvent","addEventListener","ReactNativeWebView","postMessage","JSON","stringify","styleAttribute","style","height","hasChildNodes","innerHTML","appendChild","getDomElement","getElementById","contentWindow","clear","remove","removeChild","Error","value","id","error","message","ExtentElementList","CONFIG","ELEMENTS","cardNumber","expiry","cvc","threeDsFrictionless","threeDsChallenge","paymentRequestButton","card","wechat","qrcode","redirect","dropIn","fullFeaturedCard","destroyElement","includes","destroy","console","warn","getElement","setElement","element","ThreeDsFrictionlessElement","confirmResponse","super","encodeURIComponent","locale","ThreeDsChallengeElement","challengeWindowSize","customizeChallengeWindowSize","CHALLENGE_WINDOW_SIZE_MAP","authPopupWidth","popupWidth","authPopupHeight","popupHeight","useDefaultStyle","challengeDiv","customizeAuthFormContainer","customizeGatewayUrl","intentData","threeDsPromise","resolver","reject","awaiting","clear3Ds","querySelector","clearThreeDsPromise","frictionlessHandler","eventData","isHppOrApi","location","log","Date","toLocaleTimeString","body","customizePopupWidth","customizePopupHeight","intent","challengeHandler","mount","setTimeout","01","02","03","04","05","getBrowserInfo","fingerprintRequest","navigator","screen","language","colorDepth","width","intent_id","env","device_id","getDeviceFingerprint","screen_height","screen_width","screen_color_depth","timezone","getTimezoneOffset","browser","java_enabled","javaEnabled","javascript_enabled","user_agent","userAgent","fraudSessionId","ORG_ID","script","now","src","get3dsReturnUrl","props","checkoutOrigin","handle3ds","cardBin","next_action","authFormContainer","componentType","frictionlessDiv","Promise","resolve","threeDsHandler","getGatewayUrl","STATIC_JS_URL","join","loadAirwallexJs","headOrBody","head","loadAirwallex","then","Airwallex","init","redirectToCheckout","confirmPaymentIntent","async","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_secret","getPaymentIntent","createPaymentConsent"],"mappings":";AAqBO,MAUMA,EAAW,CACtBC,KAAM,yBACNC,KAAM,8BACNC,QAAS,iCAKTC,GAAI,uBACJC,QAAS,4BACTC,IAAK,kBAGMC,EAA2B,CACtCN,KAAM,gCACNC,KAAM,qCACNC,QAAS,wCAKTC,GAAI,mCACJC,QAAS,wCACTC,IAAK,+BClDME,EAMXC,YAAYC,EAAoBC,SDWCC,ECV/BC,KAAKC,WAAa,KAClBD,KAAKH,WAAaA,EAClBG,KAAKF,QAAUA,EACfE,KAAKE,OAASC,OAAOC,SAASC,cAAc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J,OAAOwJ,UAAUU,qBAAqB3J,GALxB,CACrB,MAAMsJ,EAAM,wDAEZ,MADArG,QAAQpB,MAAMyH,GACR,IAAI5H,MAAM4H"}
1
+ {"version":3,"file":"airwallex.es.js","sources":["../../src/index.ts"],"sourcesContent":["import Airwallex, {\n init as initFn,\n redirectToCheckout as redirectToCheckoutFn,\n createElement as createElementFn,\n destroyElement as destroyElementFn,\n getElement as getElementFn,\n confirmPaymentIntent as confirmPaymentIntentFn,\n confirmPaymentIntentWithSavedCard as confirmPaymentIntentWithSavedCardFn,\n createPaymentMethod as createPaymentMethodFn,\n getPaymentIntent as getPaymentIntentFn,\n createPaymentConsent as createPaymentConsentFn,\n AirwallexEnv,\n} from '../types/airwallex';\nimport {\n getBrowserInfo as getBrowserInfoFn,\n getDeviceFingerprint as getDeviceFingerprintFn,\n get3dsReturnUrl as get3dsReturnUrlFn,\n handle3ds as handle3dsFn,\n} from '../types/fraud';\nimport { loadAirwallex as loadAirwallexFn } from '../types/index';\n\nconst ENV_HOST = {\n prod: 'checkout.airwallex.com',\n demo: 'checkout-demo.airwallex.com',\n staging: 'checkout-staging.airwallex.com',\n /**\n * Below env only for the npm package development\n * Should not using them when integrate with Airwallex\n */\n qa: 'checkoutui.qa.awx.im',\n preview: 'checkoutui.preview.awx.im',\n dev: 'localhost:3000',\n};\n\ndeclare global {\n interface Window {\n Airwallex: Airwallex;\n ReactNativeWebView: {\n postMessage: (message: string) => void;\n };\n }\n}\n\nexport const getGatewayUrl = (env: AirwallexEnv): string => `https://${ENV_HOST[env] || ENV_HOST.prod}`;\n\nconst STATIC_JS_URL = `/assets/elements.bundle.min.js`;\n\nexport const loadAirwallexJs = (gatewayUrl: string): HTMLScriptElement => {\n const script = document.createElement('script');\n script.src = `${gatewayUrl}${STATIC_JS_URL}`;\n\n const headOrBody = document.head || document.body;\n\n if (!headOrBody) {\n throw new Error('Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.');\n }\n\n headOrBody.appendChild(script);\n\n return script;\n};\n\nexport const loadAirwallex: typeof loadAirwallexFn = (options) => {\n return Promise.resolve().then(() => {\n if (typeof window === 'undefined') {\n return null;\n }\n if (window.Airwallex) {\n return window.Airwallex;\n }\n\n const script: HTMLScriptElement =\n document.querySelector(`script[src=\"${STATIC_JS_URL}\"], script[src=\"${STATIC_JS_URL}/\"]`) ||\n loadAirwallexJs(getGatewayUrl(options?.env || 'prod'));\n\n return new Promise((resolve, reject) => {\n script.addEventListener('load', () => {\n if (window.Airwallex) {\n window.Airwallex.init(options);\n resolve(window.Airwallex);\n } else {\n reject(new Error('Failed to load Airwallex on load event'));\n }\n });\n\n script.addEventListener('error', () => {\n reject(new Error('Failed to load Airwallex scripts'));\n });\n });\n });\n};\n\nexport const init: typeof initFn = (options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before init();');\n } else {\n window.Airwallex.init(options);\n }\n};\n\nexport const redirectToCheckout: typeof redirectToCheckoutFn = (props) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before redirectToCheckout();');\n } else {\n window.Airwallex.redirectToCheckout(props);\n }\n};\n\nexport const createElement: typeof createElementFn = (type, options) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before createElement();');\n return null;\n } else {\n return window.Airwallex.createElement(type, options);\n }\n};\n\nexport const destroyElement: typeof destroyElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before destroyElement();');\n return false;\n } else {\n return window.Airwallex.destroyElement(type);\n }\n};\n\nexport const getElement: typeof getElementFn = (type) => {\n if (!window.Airwallex) {\n console.error('Please loadAirwallex() before getElement();');\n return null;\n } else {\n return window.Airwallex.getElement(type);\n }\n};\n\nexport const confirmPaymentIntent: typeof confirmPaymentIntentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntent(data);\n }\n};\n\nexport const confirmPaymentIntentWithSavedCard: typeof confirmPaymentIntentWithSavedCardFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before confirmPaymentIntentWithSavedCard();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.confirmPaymentIntentWithSavedCard(data);\n }\n};\n\nexport const createPaymentMethod: typeof createPaymentMethodFn = async (client_secret, data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentMethod();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentMethod(client_secret, data);\n }\n};\n\nexport const getPaymentIntent: typeof getPaymentIntentFn = async (id, client_secret) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before getPaymentIntent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.getPaymentIntent(id, client_secret);\n }\n};\n\nexport const createPaymentConsent: typeof createPaymentConsentFn = async (data) => {\n if (!window.Airwallex) {\n const err = 'Please loadAirwallex() before createPaymentConsent();';\n console.error(err);\n throw new Error(err);\n } else {\n return window.Airwallex.createPaymentConsent(data);\n }\n};\n\nexport const getBrowserInfo: typeof getBrowserInfoFn = (data) => {\n return window.Airwallex.getBrowserInfo(data);\n};\n\nexport const getDeviceFingerprint: typeof getDeviceFingerprintFn = (data) => {\n return window.Airwallex.getDeviceFingerprint(data);\n};\n\nexport const get3dsReturnUrl: typeof get3dsReturnUrlFn = (data) => {\n return window.Airwallex.get3dsReturnUrl(data);\n};\n\nexport const handle3ds: typeof handle3dsFn = (data) => {\n return window.Airwallex.handle3ds(data);\n};\n"],"names":["ENV_HOST","prod","demo","staging","qa","preview","dev","getGatewayUrl","env","STATIC_JS_URL","loadAirwallexJs","gatewayUrl","script","document","createElement","src","headOrBody","head","body","Error","appendChild","loadAirwallex","options","Promise","resolve","then","window","Airwallex","querySelector","reject","addEventListener","init","console","error","redirectToCheckout","props","type","destroyElement","getElement","confirmPaymentIntent","async","data","err","confirmPaymentIntentWithSavedCard","createPaymentMethod","client_secret","getPaymentIntent","id","createPaymentCon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P,GAMEK,EAAmCF,GACzCV,OAAOC,UAIHD,OAAOC,UAAUW,WAAWF,IAHnCJ,QAAQC,MAAM,+CACP,MAMEM,EAAsDC,MAAOC,IACxE,GAAKf,OAAOC,UAKV,OAAOD,OAAOC,UAAUY,qBAAqBE,GALxB,CACrB,MAAMC,EAAM,wDAEZ,MADAV,QAAQC,MAAMS,GACR,IAAIvB,MAAMuB,KAMPC,EAAgFH,MAAOC,IAClG,GAAKf,OAAOC,UAKV,OAAOD,OAAOC,UAAUgB,kCAAkCF,GALrC,CACrB,MAAMC,EAAM,qEAEZ,MADAV,QAAQC,MAAMS,GACR,IAAIvB,MAAMuB,KAMPE,EAAoDJ,MAAOK,EAAeJ,KACrF,GAAKf,OAAOC,UAKV,OAAOD,OAAOC,UAAUiB,oBAAoBC,EAAeJ,GALtC,CACrB,MAAMC,EAAM,uDAEZ,MADAV,QAAQC,MAAMS,GACR,IAAIvB,MAAMuB,KAMPI,EAA8CN,MAAOO,EAAIF,KACpE,GAAKnB,OAAOC,UAKV,OAAOD,OAAOC,UAAUmB,iBAAiBC,EAAIF,GALxB,CACrB,MAAMH,EAAM,oDAEZ,MADAV,QAAQC,MAAMS,GACR,IAAIvB,MAAMuB,KAMPM,EAAsDR,MAAOC,IACxE,GAAKf,OAAOC,UAKV,OAAOD,OAAOC,UAAUqB,qBAAqBP,GALxB,CACrB,MAAMC,EAAM,wDAEZ,MADAV,QAAQC,MAAMS,GACR,IAAIvB,MAAMuB,KAMPO,EAA2CR,GAC/Cf,OAAOC,UAAUsB,eAAeR,GAG5BS,EAAuDT,GAC3Df,OAAOC,UAAUuB,qBAAqBT,GAGlCU,EAA6CV,GACjDf,OAAOC,UAAUwB,gBAAgBV,GAG7BW,EAAiCX,GACrCf,OAAOC,UAAUyB,UAAUX"}
@@ -1,4 +1,3 @@
1
- /* Airwallex Checkout Component Version [0.2.40] */
2
- var Airwallex=function(e){"use strict";const t={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},n={prod:"https://pci-api.airwallex.com",demo:"https://pci-api-demo.airwallex.com",staging:"https://pci-api-staging.airwallex.com",qa:"https://pci-api-qa.airwallex.com",preview:"https://pci-api-preview.airwallex.com",dev:"http://localhost:8080"};class i{constructor(e,t){var n,i;this.domElement=null,this.gatewayUrl=e,this.options=t,this.iframe=window.document.createElement("iframe"),this.iframe.setAttribute("frameborder","0"),this.iframe.setAttribute("allowtransparency","true"),this.iframe.setAttribute("importance","high"),this.iframe.setAttribute("scrolling","no"),this.iframe.setAttribute("allowpaymentrequest","true"),null===(n=this.iframe)||void 0===n||n.setAttribute("style","\n height: 0;\n width: 100%;\n display: block;\n "),i=e=>{var t,n,i;if(e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)){const t=new CustomEvent(null===(n=e.data)||void 0===n?void 0:n.code,{detail:{type:null===(i=e.data)||void 0===i?void 0:i.type},bubbles:!0,composed:!0});window.document.dispatchEvent(t)}},window.addEventListener("message",(e=>{window.ReactNativeWebView&&window.ReactNativeWebView.postMessage(JSON.stringify(e.data)),i(e)}))}addResizeListener(e){window.addEventListener("message",(t=>{var n,i,o,l;if(t.origin===this.gatewayUrl&&t.isTrusted&&"onResize"===(null===(n=t.data)||void 0===n?void 0:n.code)&&e===(null===(i=t.data)||void 0===i?void 0:i.type)){const e=null===(o=this.iframe)||void 0===o?void 0:o.style;e&&(e.height=`${null===(l=t.data)||void 0===l?void 0:l.height}px`)}}))}mount(e){if("string"!=typeof e)return(null==e?void 0:e.hasChildNodes())&&(e.innerHTML=""),this.iframe&&e.appendChild(this.iframe),this.domElement=e,e;{const t=window.document.getElementById(e);return(null==t?void 0:t.hasChildNodes())&&(t.innerHTML=""),this.iframe&&(null==t||t.appendChild(this.iframe)),t&&(this.domElement=t),t}}blur(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"blur"},this.gatewayUrl)}clear(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"clear"},this.gatewayUrl)}destroy(){var e;this.clear(),null===(e=this.iframe)||void 0===e||e.remove(),this.iframe=null}focus(){var e,t;null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"focus"},this.gatewayUrl)}unmount(){var e;this.clear(),this.iframe&&(null===(e=this.domElement)||void 0===e||e.removeChild(this.iframe))}update(e){var t,n;this.options={...this.options,...e},null===(n=null===(t=this.iframe)||void 0===t?void 0:t.contentWindow)||void 0===n||n.postMessage({code:"update",options:e},this.gatewayUrl)}async confirm(){throw new Error("Confirm is not supported in ElementBase")}success(e){throw new Error(`Call success with ${e.id} is not supported in ElementBase`)}fail(e){throw new Error(`Call fail with ${e.code}: ${e.message} is not supported in ElementBase`)}}const o=["cardNumber","expiry","cvc","paymentRequestButton","card","wechat","qrcode","redirect","dropIn","fullFeaturedCard","threeDsFrictionless","threeDsChallenge"],l={},r={cardNumber:null,expiry:null,cvc:null,threeDsFrictionless:null,threeDsChallenge:null,paymentRequestButton:null,card:null,wechat:null,qrcode:null,redirect:null,dropIn:null,fullFeaturedCard:null},a=e=>{var t;return o.includes(e)?(null===(t=r[e])||void 0===t||t.destroy(),r[e]=null,!0):(console.warn(`destroyElement with type: ${e} not support!`),!1)},s=e=>o.includes(e)?r[e]:(console.warn(`getElement with type: ${e} not support!`),null),d=(e,t)=>o.includes(e)?(r[e]=t,!0):(console.warn(`destroyElement with type: ${e} not support!`),!1);class c extends i{constructor(e,t,n){var i,o,r,a;super(e,n),this.confirmResponse=t,null===(i=this.iframe)||void 0===i||i.setAttribute("src",`${e}/#/elements/3ds-frictionless?options=${encodeURIComponent(JSON.stringify(this.options))}&lang=${null===(o=l)||void 0===o?void 0:o.locale}`),null===(r=this.iframe)||void 0===r||r.setAttribute("name","Airwallex 3DS frictionless iframe"),null===(a=this.iframe)||void 0===a||a.setAttribute("title","Airwallex 3DS frictionless iframe"),window.addEventListener("message",(e=>{var t,n,i,o;e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)&&"threeDsFrictionless"===(null===(n=e.data)||void 0===n?void 0:n.type)&&(null===(o=null===(i=this.iframe)||void 0===i?void 0:i.contentWindow)||void 0===o||o.postMessage({code:"update",data:this.confirmResponse},this.gatewayUrl))}))}async confirm(){var e,t;return null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"confirm",data:this.confirmResponse},this.gatewayUrl),null}}class u extends i{constructor(e,t,n){var i,o,l,r,a,s,d,c,u;super(e,n),this.confirmResponse=t;const w=(null==n?void 0:n.customizeChallengeWindowSize)&&S[null==n?void 0:n.customizeChallengeWindowSize]?S[null==n?void 0:n.customizeChallengeWindowSize]:S["05"],h=(null===(i=null==n?void 0:n.style)||void 0===i?void 0:i.popupWidth)?`${null===(o=null==n?void 0:n.style)||void 0===o?void 0:o.popupWidth}px`:w[0],m=(null===(l=null==n?void 0:n.style)||void 0===l?void 0:l.popupHeight)?`${null===(r=null==n?void 0:n.style)||void 0===r?void 0:r.popupHeight}px`:w[1];null===(a=this.iframe)||void 0===a||a.setAttribute("src",`${e}/#/elements/3ds-challenge?options=${encodeURIComponent(JSON.stringify(this.options))}`),null===(s=this.iframe)||void 0===s||s.setAttribute("name","Airwallex 3DS challenge iframe"),null===(d=this.iframe)||void 0===d||d.setAttribute("title","Airwallex 3DS challenge iframe"),null===(c=this.iframe)||void 0===c||c.setAttribute("scrolling","yes"),null===(u=this.iframe)||void 0===u||u.setAttribute("style",`\n background: #fff;\n width: ${h};\n height: ${m};\n position: ${(null==n?void 0:n.useDefaultStyle)?"absolute":"relative"};\n top: ${(null==n?void 0:n.useDefaultStyle)?"50%":"0"};\n left: ${(null==n?void 0:n.useDefaultStyle)?"50%":"0"};\n transform: ${(null==n?void 0:n.useDefaultStyle)?"translate(-50%, -50%)":"none"};\n border-radius: ${(null==n?void 0:n.useDefaultStyle)?"4px":"0"};\n `),window.addEventListener("message",(e=>{var t,n,i,o;e.origin===this.gatewayUrl&&e.isTrusted&&"onReady"===(null===(t=e.data)||void 0===t?void 0:t.code)&&"threeDsChallenge"===(null===(n=e.data)||void 0===n?void 0:n.type)&&(null===(o=null===(i=this.iframe)||void 0===i?void 0:i.contentWindow)||void 0===o||o.postMessage({code:"update",data:this.confirmResponse},this.gatewayUrl))}))}async confirm(){var e,t;return null===(t=null===(e=this.iframe)||void 0===e?void 0:e.contentWindow)||void 0===t||t.postMessage({code:"confirm",data:this.confirmResponse},this.gatewayUrl),null}}const w="threeDsFrictionless",h="threeDsChallenge";let m,v,p,g,f,y;const x={resolver:null,reject:null,awaiting:!1},A=e=>{var t;null===(t=document.querySelector(`#${e}`))||void 0===t||t.remove(),a(e===w?w:h)},b=()=>{x.awaiting=!1,x.resolver=null,x.reject=null},E=e=>{var t,n,i;const o="data"in e?e.data:e.detail,l=["hpp","api"].includes(p),r=l?null:s(p),a=(null==r?void 0:r.gatewayUrl)||window.location.origin;("data"in e&&e.origin===a&&e.isTrusted||l)&&(null==o?void 0:o.type)===w&&(A(h),"onSuccess"===(null==o?void 0:o.code)&&(console.log("frictionlessHandler onSuccess",(new Date).toLocaleTimeString()),null===(t=x.resolver)||void 0===t||t.call(x,o),b(),A(w)),["onError","onChallengeError"].includes(null==o?void 0:o.code)&&(console.log(`frictionlessHandler ${null==o?void 0:o.code}`,(new Date).toLocaleTimeString()),null===(n=x.reject)||void 0===n||n.call(x,o),b(),A(w)),"onChallenge"===(null==o?void 0:o.code)&&(console.log("frictionlessHandler onChallenge threeDsFrictionlessType",(new Date).toLocaleTimeString()),A(w),v?m=v:(m=document.createElement("div"),m.setAttribute("id",h),m.setAttribute("style","\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 0;\n z-index: 1500;\n overflow: hidden;\n background: rgba(0, 0, 0, 0.75);\n "),document.body.appendChild(m)),d(h,new u(f,o,{origin:window.location.origin,style:{popupWidth:undefined,popupHeight:undefined},useDefaultStyle:null===v,customizeChallengeWindowSize:g,intent:y})),window.addEventListener("message",C),null===(i=s(h))||void 0===i||i.mount(m)))},C=e=>{var t,n;const i="data"in e?e.data:e.detail,o=["hpp","api"].includes(p),l=o?null:s(p),r=(null==l?void 0:l.gatewayUrl)||window.location.origin;("data"in e&&e.origin===r&&e.isTrusted||o)&&(null==i?void 0:i.type)===h&&("onReady"===(null==i?void 0:i.code)&&(console.log("challengeHandler onReady",(new Date).toLocaleTimeString()),setTimeout((()=>{m.style.height="100%"}),2e3)),"onChallengeSuccess"===(null==i?void 0:i.code)&&(m.style.height="0"),"onSuccess"===(null==i?void 0:i.code)&&(console.log("challengeHandler onSuccess",(new Date).toLocaleTimeString()),null===(t=x.resolver)||void 0===t||t.call(x,i),b(),A(h)),["onError","onChallengeError"].includes(null==i?void 0:i.code)&&(console.log(`challengeHandler ${null==i?void 0:i.code}`,(new Date).toLocaleTimeString()),null===(n=x.reject)||void 0===n||n.call(x,i),b(),A(h)))},S={"01":["250px","400px"],"02":["390px","400px"],"03":["500px","600px"],"04":["600px","400px"],"05":["100%","100%"]};let $="";const D=({intent_id:e="",env:t="prod"})=>{if(!$.includes(e)){const n="prod"===t?"9ozphlqx":"45ssiuz3",i=document.createElement("script");$=`${e}${Date.now()}`,i.src=`https://h.online-metrix.net/fp/tags.js?org_id=${n}&session_id=${$}`,document.body.appendChild(i)}return $},P=e=>`https://${t[e]||"checkout.airwallex.com"}`,T=`/assets/bundle.${[0,2,40].join(".")}.min.js`,W=e=>{const t=document.createElement("script");t.src=`${e}${T}`;const n=document.head||document.body;if(!n)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return n.appendChild(t),t};return e.confirmPaymentIntent=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},e.confirmPaymentIntentWithSavedCard=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},e.createElement=(e,t)=>window.Airwallex?window.Airwallex.createElement(e,t):(console.error("Please loadAirwallex() before createElement();"),null),e.createPaymentConsent=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},e.createPaymentMethod=async(e,t)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,t);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},e.destroyElement=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),e.get3dsReturnUrl=e=>{const{env:i,checkoutOrigin:o}=e;return`${n[i||"prod"]}/api/v1/checkout/elements/3ds?origin=https://${t[i||"prod"]}&checkoutOrigin=${o||window.location.origin}`},e.getBrowserInfo=e=>{const{navigator:t,screen:n}=window||{},{language:i}=t||{},{colorDepth:o,height:l,width:r}=n||{},{intent_id:a,env:s}=e||{};let d;return e&&(d=D({intent_id:a,env:s})),{device_id:d,screen_height:l,screen_width:r,screen_color_depth:o,language:i,timezone:(new Date).getTimezoneOffset(),browser:{java_enabled:window.navigator.javaEnabled(),javascript_enabled:!0,user_agent:t.userAgent}}},e.getDeviceFingerprint=D,e.getElement=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),e.getGatewayUrl=P,e.getPaymentIntent=async(e,t)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,t);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},e.handle3ds=e=>{const{cardBin:n,next_action:i,authFormContainer:o,intent:l,challengeWindowSize:r,env:a}=e;return(({intent:e,gatewayUrl:t,cardBin:n,next_action:i,authFormContainer:o,componentType:l,challengeWindowSize:r})=>{var a;x.awaiting&&console.warn("Should wait previous 3ds flow finished before execute new one!"),console.log("threeDsHandler onChallenge type",(new Date).toLocaleTimeString()),v=document.getElementById(o||""),p=l,g=r,f=t,y=e,A(w),d(w,new c(f,{code:"",type:w,cardBin:n,next_action:i},{intent:y,origin:window.location.origin}));const u=document.createElement("div");return u.setAttribute("id",w),document.body.appendChild(u),window.addEventListener("message",E),null===(a=s(w))||void 0===a||a.mount(u),new Promise(((e,t)=>{x.resolver=e,x.reject=t,x.awaiting=!0}))})({gatewayUrl:`https://${t[a]}`,cardBin:n,intent:l,next_action:i,authFormContainer:o,componentType:"api",challengeWindowSize:r})},e.init=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},e.loadAirwallex=e=>Promise.resolve().then((()=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;const t=document.querySelector(`script[src="${T}"], script[src="${T}/"]`)||W(P((null==e?void 0:e.env)||"prod"));return new Promise(((n,i)=>{t.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),n(window.Airwallex)):i(new Error("Failed to load Airwallex on load event"))})),t.addEventListener("error",(()=>{i(new Error("Failed to load Airwallex scripts"))}))}))})),e.loadAirwallexJs=W,e.redirectToCheckout=e=>{window.Airwallex?window.Airwallex.redirectToCheckout(e):console.error("Please loadAirwallex() before redirectToCheckout();")},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
3
- /* Airwallex @Charlie.Lang */
1
+ /* Airwallex Checkout Component Version [0.2.49] */
2
+ var Airwallex=function(e){"use strict";const r={prod:"checkout.airwallex.com",demo:"checkout-demo.airwallex.com",staging:"checkout-staging.airwallex.com",qa:"checkoutui.qa.awx.im",preview:"checkoutui.preview.awx.im",dev:"localhost:3000"},n=e=>`https://${r[e]||r.prod}`,o="/assets/elements.bundle.min.js",l=e=>{const r=document.createElement("script");r.src=`${e}${o}`;const n=document.head||document.body;if(!n)throw new Error("Airwallex payment scripts requires a <head> or <body> html element in order to be loaded.");return n.appendChild(r),r};return e.confirmPaymentIntent=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntent(e);{const e="Please loadAirwallex() before confirmPaymentIntent();";throw console.error(e),new Error(e)}},e.confirmPaymentIntentWithSavedCard=async e=>{if(window.Airwallex)return window.Airwallex.confirmPaymentIntentWithSavedCard(e);{const e="Please loadAirwallex() before confirmPaymentIntentWithSavedCard();";throw console.error(e),new Error(e)}},e.createElement=(e,r)=>window.Airwallex?window.Airwallex.createElement(e,r):(console.error("Please loadAirwallex() before createElement();"),null),e.createPaymentConsent=async e=>{if(window.Airwallex)return window.Airwallex.createPaymentConsent(e);{const e="Please loadAirwallex() before createPaymentConsent();";throw console.error(e),new Error(e)}},e.createPaymentMethod=async(e,r)=>{if(window.Airwallex)return window.Airwallex.createPaymentMethod(e,r);{const e="Please loadAirwallex() before createPaymentMethod();";throw console.error(e),new Error(e)}},e.destroyElement=e=>window.Airwallex?window.Airwallex.destroyElement(e):(console.error("Please loadAirwallex() before destroyElement();"),!1),e.get3dsReturnUrl=e=>window.Airwallex.get3dsReturnUrl(e),e.getBrowserInfo=e=>window.Airwallex.getBrowserInfo(e),e.getDeviceFingerprint=e=>window.Airwallex.getDeviceFingerprint(e),e.getElement=e=>window.Airwallex?window.Airwallex.getElement(e):(console.error("Please loadAirwallex() before getElement();"),null),e.getGatewayUrl=n,e.getPaymentIntent=async(e,r)=>{if(window.Airwallex)return window.Airwallex.getPaymentIntent(e,r);{const e="Please loadAirwallex() before getPaymentIntent();";throw console.error(e),new Error(e)}},e.handle3ds=e=>window.Airwallex.handle3ds(e),e.init=e=>{window.Airwallex?window.Airwallex.init(e):console.error("Please loadAirwallex() before init();")},e.loadAirwallex=e=>Promise.resolve().then((()=>{if("undefined"==typeof window)return null;if(window.Airwallex)return window.Airwallex;const r=document.querySelector(`script[src="${o}"], script[src="${o}/"]`)||l(n((null==e?void 0:e.env)||"prod"));return new Promise(((n,o)=>{r.addEventListener("load",(()=>{window.Airwallex?(window.Airwallex.init(e),n(window.Airwallex)):o(new Error("Failed to load Airwallex on load event"))})),r.addEventListener("error",(()=>{o(new Error("Failed to load Airwallex scripts"))}))}))})),e.loadAirwallexJs=l,e.redirectToCheckout=e=>{window.Airwallex?window.Airwallex.redirectToCheckout(e):console.error("Please loadAirwallex() before redirectToCheckout();")},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
4
3
  //# sourceMappingURL=airwallex.iife.js.map