@gr4vy/secure-fields 2.3.0--canary.1104.46d8e0a.0 → 2.3.0
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.
- package/CHANGELOG.md +22 -0
- package/lib/index.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# v2.3.0 (Wed Mar 18 2026)
|
|
2
|
+
|
|
3
|
+
#### 🚀 Enhancement
|
|
4
|
+
|
|
5
|
+
- 3DS on Secure Fields [#1104](https://github.com/gr4vy/secure-fields/pull/1104) ([@GiordanoArman](https://github.com/GiordanoArman) [@luca-gr4vy](https://github.com/luca-gr4vy) [@gryevns](https://github.com/gryevns))
|
|
6
|
+
- feat: expose field clear method [#1103](https://github.com/gr4vy/secure-fields/pull/1103) ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
7
|
+
|
|
8
|
+
#### 🏠 Internal
|
|
9
|
+
|
|
10
|
+
- chore(dev-deps): update dependency msw to ^2.12.11 [#1141](https://github.com/gr4vy/secure-fields/pull/1141) ([@renovate[bot]](https://github.com/renovate[bot]))
|
|
11
|
+
- fix: various vulnerabilities [#1119](https://github.com/gr4vy/secure-fields/pull/1119) ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
12
|
+
- task: upgrade to eslint v9 [#1110](https://github.com/gr4vy/secure-fields/pull/1110) ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
13
|
+
|
|
14
|
+
#### Authors: 4
|
|
15
|
+
|
|
16
|
+
- [@renovate[bot]](https://github.com/renovate[bot])
|
|
17
|
+
- Gary Evans ([@gryevns](https://github.com/gryevns))
|
|
18
|
+
- GiordanoArman ([@GiordanoArman](https://github.com/GiordanoArman))
|
|
19
|
+
- Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
1
23
|
# v2.2.6 (Thu Feb 19 2026)
|
|
2
24
|
|
|
3
25
|
#### 🐛 Bug Fix
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Events:()=>i,SecureFields:()=>Z,SecureInput:()=>V});var r=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()),n="@gr4vy-secure-fields-debug",i=function(e){return e.CARD_VAULT_SUCCESS="card-vault-success",e.CARD_VAULT_FAILURE="card-vault-failure",e.FORM_CHANGE="form-change",e.METHOD_CHANGE="method-change",e.READY="ready",e.RESIZE="resize",e.CLICK_TO_PAY_INITIALIZED="click-to-pay-initialized",e.CLICK_TO_PAY_READY="click-to-pay-ready",e.CLICK_TO_PAY_SIGN_OUT="click-to-pay-sign-out",e.CLICK_TO_PAY_ERROR="click-to-pay-error",e.CLICK_TO_PAY_CANCEL="click-to-pay-cancel",e.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD="click-to-pay-checkout-with-new-card",e.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA="click-to-pay-unable-to-load-dpa",e.CLICK_TO_PAY_VISIBILITY_CHANGE="click-to-pay:visibility-change",e.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE="click-to-pay-card-form:visibility-change",e.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE="click-to-pay-sign-in:visibility-change",e.CLICK_TO_PAY_PROCESSING="click-to-pay-processing",e.CLICK_TO_PAY_AUTHENTICATE="click-to-pay-authenticate",e.CLICK_TO_PAY_AUTHENTICATE_FAILURE="click-to-pay-authenticate-failure",e.THREE_DS_START="three-ds-start",e.THREE_DS_FINISH="three-ds-finish",e}({}),o=function(e){return e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port",e.REQUEST_RECOGNITION_TOKEN="request-recognition-token",e.REQUEST_RECOGNITION_TOKEN_FAILED="request-recognition-token-failed",e.RECOGNITION_TOKEN="recognition-token",e}({}),a=function(e){return e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled",e}({}),s=function(e){return e.PAYMENT_METHOD_ID_IN_USE="You're passing a paymentMethodId to use a stored payment method, which means Secure Fields methods `addCardNumber`, `addExpiryDate` and `addClickToPay` are automatically disabled and won't render the related fields",e.PAYMENT_METHOD_ID_DEPRECATED="The 'paymentMethodId' prop is deprecated and will be removed in a future version. Please use the 'paymentMethod' prop instead: { paymentMethod: { id: 'your-id', scheme: 'visa' } }",e.FIELD_PATTERN_IN_USE="The `pattern` option can't be used on card fields, so it won't be applied here.",e.NO_RECOGNITION_TOKEN="The recognition token couldn't be obtained or the request took too much time. It is possible that a Click to Pay user was therefore not recognised.",e}({}),c="secure-fields",l={number:"addCardNumberField",expiryDate:"addExpiryDateField",securityCode:"addSecurityCodeField"},d=["01","02","03","04","05"];function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return u(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var p=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=h(r,2),i=n[0],o=n[1];return i!==e||o.toString()!==t.toString()}))}unsubscribeAll(){this.subscribers=[]}publish(e,t){this.subscribers.forEach((r=>{var n=h(r,2),i=n[0],o=n[1];return setTimeout((()=>i===e?o(t):null),0)}))}constructor(){var e,t;t=void 0,(e="subscribers")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t,this.subscribers=[]}};function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var f=new class{add(e,t,r){window.addEventListener(e,t),this.listeners.push([e,t,r])}remove(e,t,r){var n=this.listeners.findIndex((n=>{var i=m(n,3),o=i[0],a=i[1],s=i[2];return o===e&&a.toString()===t.toString()&&s===r}));if(-1!==n){var i=m(this.listeners.splice(n,1),1),o=m(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=m(e,2),r=t[0],n=t[1];window.removeEventListener(r,n)})),this.listeners=[]}constructor(){var e,t;t=[],(e="listeners")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},b=e=>{var t,r;if(null===(t=document)||void 0===t?void 0:t.cookie)return null===(r="; ".concat(document.cookie).match(";\\s*".concat(e,"=([^;]+)")))||void 0===r?void 0:r[1]},v=["accesskey","autocapitalize","autocomplete","autofocus","aria-.","class","contenteditable","data-.","dir","draggable","enterkeyhint","hidden","id","inert","inputmode","is","itemid","itemprop","itemref","itemscope","itemtype","lang","nonce","onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onmousewheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onsort","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting","popover","role","slot","spellcheck","style","tabindex","title","translate"],_=(e,t)=>e&&(e.style.display=t?"block":"none");function I(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function g(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){I(e,t,r[t])}))}return e}var O={debug:!1,level:"log"},C=(e,t,r)=>{var i=g({},O,r),o=i.debug,a=i.level;(o||"true"===localStorage.getItem(n))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},E=(e,t,r)=>{var n,i;C(e,t,(n=g({},r),i=null!=(i={level:"warn"})?i:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(i)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})),n))},T=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var P=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,i)=>{var o,a,s=(a=2,function(e){if(Array.isArray(e))return e}(o=i)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(o,a)||function(e,t){if(e){if("string"==typeof e)return A(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?A(e,t):void 0}}(o,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),c=s[0],l=s[1];return(e=>"[object Object]"===Object.prototype.toString.call(e))(l)?n.push(...e(t[c],"".concat((r+c).match(/[a-zA-Z0-9]+/g).join("-"),"-"))):(c=T(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function S(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function w(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){w(e,t,r[t])}))}return e}function k(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class L{init(e,t){var n;this.challengeWindowSize=d.includes(null==t?void 0:t.challengeWindowSize)?t.challengeWindowSize:"05",this.element="string"==typeof e?document.querySelector(e):e;var i="gr4vy-threeds-flow-controller";null===(n=document.body.querySelector("iframe#".concat(i)))||void 0===n||n.remove();var o=document.createElement("iframe");o.id=i,o.title="ThreeDSecure",o.style.display="block",o.style.border="0px",o.style.padding="0px",o.style.margin="0px",o.style.width="100%",o.style.height="100%",o.src=r(this.secureFields.frameUrl+"/threeds.html",{sessionId:this.secureFields.config.sessionId,parentOrigin:this.secureFields.parentOrigin,gr4vyId:this.secureFields.config.gr4vyId,environment:this.secureFields.config.environment}),this.element.appendChild(o),this.controller=o;var a={type:"three-ds-init",channel:c,data:{challengeWindowSize:this.challengeWindowSize}};return o.addEventListener("load",(()=>{var e;null===(e=o.contentWindow)||void 0===e||e.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),this.secureFields.controller.addEventListener("load",(()=>{this.secureFields.controller.contentWindow.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),f.remove("message",this.listener.bind(this),"three-ds"),f.add("message",this.listener.bind(this),"three-ds"),this}listener(e){return(t=function*(){if(e.origin===this.secureFields.frameUrl){var t=e.data,r=t.type,n=t.data;switch(r){case i.THREE_DS_START:p.publish(i.THREE_DS_START,k(N({},n),{element:this.element})),C("3DS start",e.data.data);break;case i.THREE_DS_FINISH:p.publish(i.THREE_DS_FINISH,k(N({},n),{element:this.element})),C("3DS finish",e.data.data)}}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){S(o,n,i,a,s,"next",e)}function s(e){S(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}constructor(e){w(this,"secureFields",void 0),w(this,"controller",void 0),w(this,"challengeWindowSize",void 0),w(this,"element",void 0),this.secureFields=e}}function D(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}class R extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function j(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function U(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){j(o,n,i,a,s,"next",e)}function s(e){j(o,n,i,a,s,"throw",e)}a(void 0)}))}}function M(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(){return F=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},F.apply(this,arguments)}function Y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){M(e,t,r[t])}))}return e}class K{_addIframe(e,t,n,i){var o=document.createElement("iframe");return o.id=e,o.title=t,o.setAttribute("width","100%"),o.setAttribute("frameborder","0"),o.setAttribute("style","height:0px"),o.src=r(n,i),o}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,a=r.data,l=a.type,d=a.data;switch(n){case this.origin:switch(l){case i.RESIZE:this.controller.style.height="".concat(d.height>0?d.height+48:0,"px");break;case i.METHOD_CHANGE:var u=d.method||"card";(this.secureFields.method!==u||t)&&(t=!1,this.secureFields.updateMethod(u,{data:d}),_(this.cardForm,"card"===u),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===u));break;case i.CLICK_TO_PAY_INITIALIZED:p.publish(i.CLICK_TO_PAY_INITIALIZED,this.clickToPay),C("Click to Pay initialized",this.clickToPay),_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),_(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_READY:this._buyerExists=d.buyerExists,p.publish(i.CLICK_TO_PAY_READY,d),C("Click to Pay ready"),_(this.signIn,!d.buyerExists),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!d.buyerExists),_(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_SIGN_OUT:this.clickToPay.signOut();break;case i.CLICK_TO_PAY_ERROR:p.publish(i.CLICK_TO_PAY_ERROR,d),C("Click to Pay error:",d),_(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),_(this.clickToPay.element,"UNKNOWN"!==d.error),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==d.error);break;case i.CLICK_TO_PAY_CANCEL:p.publish(i.CLICK_TO_PAY_CANCEL,d),C("Click to Pay cancelled"),this._buyerExists||(_(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:p.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,d),_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),C("Click to Pay checkout with new card initiated");break;case i.CLICK_TO_PAY_PROCESSING:_(this.cardForm,!d),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,d),C("Click to Pay processing",d);break;case i.CLICK_TO_PAY_AUTHENTICATE:!function(e,t){for(var r=arguments.length,n=new Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];document.cookie="".concat(e,"=").concat(t,"; path=/; ").concat(n.join("; "))}("recognitionToken",d.recognitionToken,"Secure","SameSite=Strict","MaxAge=15552000");break;case i.CLICK_TO_PAY_AUTHENTICATE_FAILURE:p.publish(i.CLICK_TO_PAY_AUTHENTICATE_FAILURE,d),C("Click to Pay authenticate failure:",d);break;case o.REQUEST_RECOGNITION_TOKEN:this.controller.contentWindow.postMessage({channel:c,type:o.RECOGNITION_TOKEN,data:{recognitionToken:b("recognitionToken")}},this.origin);break;case o.REQUEST_RECOGNITION_TOKEN_FAILED:E(s.NO_RECOGNITION_TOKEN);break;case o.REQUEST_PORT:this.controller.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.origin,[e.port1])}break;case this.secureFields.frameUrl:l===o.REQUEST_PORT&&this.encrypt.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.secureFields.frameUrl,[e.port2])}};f.remove("message",r,"click-to-pay"),f.add("message",r,"click-to-pay")}_fetchDPA(e,t){return U((function*(e,t){var r=t.gr4vyId,n=t.environment,o=t.sessionId;try{var a=e||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(r,n);return yield function(e){return(t=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var n="".concat(t,"/digital-wallets/click-to-pay/session"),i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(i.ok){var o=yield i.json();return{srcDpaId:o.digital_payment_application_id,dpaName:o.digital_payment_application_name}}throw new R("Unable to load DPA")}catch(e){throw new R("Unable to load DPA")}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){D(o,n,i,a,s,"next",e)}function s(e){D(o,n,i,a,s,"throw",e)}a(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:a,checkoutSessionId:o})}catch(e){return C(e.message),p.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),_(this.cardForm,!0),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),_(this.clickToPay.element,!1),void p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!1)}})).apply(this,arguments)}_initConsentCheckbox(e){var t=e.checked?"click-to-pay":"card";this.secureFields.updateMethod(t,{data:{method:t}}),e.addEventListener("change",(e=>{var t=e.target;this.consent=t.checked})),f.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this.consent=!1,e.checked=!1);break;case i.METHOD_CHANGE:var r=this._buyerExists&&"card"===t.data.data.method;this.consent=r,e.checked=r}}),"click-to-pay-consent-checkbox")}_setNewCardRememberMe(e){this.controller.contentWindow.postMessage({type:"remember-me-new-card-changed",channel:c,data:{value:e}},this.origin)}_initNewCardRememberMeCheckbox(e){e.addEventListener("change",(e=>{var t=e.target;this._setNewCardRememberMe(t.checked)})),f.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_INITIALIZED:this._setNewCardRememberMe(e.checked);break;case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this._setNewCardRememberMe(!1),e.checked=!1)}}),"click-to-pay-new-card-remember-me-checkbox")}_initLearnMore(e){e.style.visibility="hidden",f.add("message",(t=>{t.data.type===i.CLICK_TO_PAY_INITIALIZED&&(e.style.visibility="visible",e.addEventListener("click",(()=>{this.controller.contentWindow.postMessage({type:"show-learn-more",channel:c},this.origin)})))}),"click-to-pay-learn-more")}init(e,t){return U((function*(){this.cardForm="string"==typeof(null==t?void 0:t.cardForm)?document.querySelector(null==t?void 0:t.cardForm):null==t?void 0:t.cardForm,this.signIn="string"==typeof(null==t?void 0:t.signIn)?document.querySelector(null==t?void 0:t.signIn):null==t?void 0:t.signIn,_(this.signIn,!1);var r=this.secureFields,n=r.apiUrl,o=r.config,a=o.gr4vyId,s=o.environment,c=o.sessionId,l=r.environmentPath;if(this.clickToPay={element:null,options:t,signIn:e=>{var t=e.email,r=e.mobileNumber;return U((function*(){var e=this.clickToPay,n=e.element,o=e.options;delete o.email,delete o.mobileNumber,n.innerHTML="",_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),_(this.cardForm,!1),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),this.secureFields.update("clickToPay",yield this.init(n,Y({},o,t?{email:t}:{},r?{mobileNumber:r}:{})))})).call(this)},signOut:()=>(this._buyerExists=!1,p.publish(i.CLICK_TO_PAY_SIGN_OUT),C("Click to pay signed out"),_(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0),document.cookie="".concat("recognitionToken","=; path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC;"),this.clickToPay.signIn({email:null,mobileNumber:null}))},!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName)){var d=yield this._fetchDPA(n,{gr4vyId:a,environment:s,sessionId:c});if(!(null==d?void 0:d.srcDpaId)&&!(null==d?void 0:d.dpaName))return;t.srcDpaId=d.srcDpaId,t.dpaName=d.dpaName}this.url=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(l).concat(a,".gr4vy.app"),this.origin=new URL(this.url).origin;var u=window.location.origin,h=(function(e){if(null==e)throw new TypeError("Cannot destructure "+e)}(t),Y({gr4vyId:a,environment:s,sessionId:c},F({},t)));if(this.controller=this._addIframe("click-to-pay-controller","Click To Pay","".concat(this.url,"/click-to-pay.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this.encrypt=this._addIframe("click-to-pay-encrypt","Click To Pay Encrypt","".concat(this.secureFields.frameUrl,"/click-to-pay-encrypt.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this._attachListeners(),null==t?void 0:t.consentCheckbox){var y="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;y&&this._initConsentCheckbox(y)}if(null==t?void 0:t.rememberMeCheckbox){var m="string"==typeof(null==t?void 0:t.rememberMeCheckbox)?document.querySelector(t.rememberMeCheckbox):null==t?void 0:t.rememberMeCheckbox;m&&this._initNewCardRememberMeCheckbox(m)}if(null==t?void 0:t.learnMoreLink){var f="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;f&&this._initLearnMore(f)}return(e="string"==typeof e?document.querySelector(e):e).appendChild(this.controller),e.appendChild(this.encrypt),this.clickToPay.element=e,this.clickToPay})).call(this)}constructor(e){M(this,"secureFields",void 0),M(this,"_buyerExists",void 0),M(this,"consent",void 0),M(this,"controller",void 0),M(this,"encrypt",void 0),M(this,"origin",void 0),M(this,"url",void 0),M(this,"cardForm",void 0),M(this,"signIn",void 0),M(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}function x(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function H(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){x(e,t,r[t])}))}return e}function G(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class V{_postMessage(e){this.frame.contentWindow.postMessage(H({channel:c},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=H({},this.options,e);var t=P(H({},this.options.styles,e.styles)),r=G(H({},this.options,e),{styles:t});this._postMessage({type:"update",data:G(H({},r),{styles:t})}),C("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}clear(){if(this.frameUrl){var e=this.type;this._postMessage({type:"reset",data:{type:e}}),C("Cleared field",{type:e})}}constructor(e){if(x(this,"frameUrl",void 0),x(this,"parentOrigin",void 0),x(this,"frame",void 0),x(this,"type",void 0),x(this,"options",void 0),x(this,"addEventListener",void 0),x(this,"removeEventListener",void 0),e){var t=e.frameUrl,r=e.parentOrigin,n=e.font,i=e.options,o=i.type,a=function(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(i,["type"]),s=e.paymentMethodScheme;this.frameUrl=t,this.parentOrigin=r,this.type=o,this.options=a;var c=P(a.styles);this.frame=document.createElement("iframe"),this.frame.id=o,this.frame.src="".concat(t,"/input.html?parentOrigin=").concat(r,"&type=").concat(this.type),this.frame.title="Secure Input",this.frame.style.display="block",this.frame.style.height="100%",this.frame.style.border="none",this.frame.style.width="100%",n&&(this.frame.src+="&font=".concat(n)),s&&(this.frame.src+="&paymentMethodScheme=".concat(s)),this.frame.onload=()=>{this._postMessage({type:"update",data:G(H({},this.options),{styles:c,type:o})}),C("Added field",this.options)}}}}function W(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function B(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function q(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){B(e,t,r[t])}))}return e}function z(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class Z{static get Events(){return i}static get version(){return"#46d8e0a4cf2c18e2d580ff6e5b19662233f80184"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),p.publish(i.METHOD_CHANGE,r),C("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:c},this.frameUrl)}_addField(e,t){var r;if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var n,i,o=document.createElement("div");n=e,i=o,Array.from(n.attributes).forEach((e=>{var t=e.name,r=e.value;v.some((e=>new RegExp(e).test(t)))&&i.setAttribute(t,r)})),(o=i).classList.add("secure-fields__input","secure-fields__input--".concat(T(t.type))),o.appendChild(t.frame),null===(r=e.parentNode)||void 0===r||r.replaceChild(o,e);var s=e=>{var r;if(e.origin===this.frameUrl&&(null===(r=e.data.data)||void 0===r?void 0:r.id)===t.type)switch(e.data.type){case"blur":p.publish("".concat(t.type,":blur"),e.data.data),o.removeAttribute(a.FOCUSED),C("Field blurred",e.data.data);break;case"focus":p.publish("".concat(t.type,":focus"),e.data.data),o.setAttribute(a.FOCUSED,""),C("Field focused",e.data.data);break;case"input":p.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?o.removeAttribute(a.INVALID):o.setAttribute(a.INVALID,""),e.data.data.autofilled?o.setAttribute(a.AUTOFILLED,""):o.removeAttribute(a.AUTOFILLED),C("Field input changed",e.data.data)}};return f.remove("message",s,t.type),f.add("message",s,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.paymentMethodId&&E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:z(q({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){var r,n;return this.securityCode||(this.securityCode=new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:z(q({label:"Security code"},this.paymentMethodId&&!(null===(r=this.config.paymentMethod)||void 0===r?void 0:r.scheme)?{lengths:[3,4]}:{},t),{type:"securityCode"}),paymentMethodScheme:null===(n=this.config.paymentMethod)||void 0===n?void 0:n.scheme})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.paymentMethodId&&E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:z(q({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addField(e,t){if(["number","expiryDate","securityCode"].includes(t.type)){t.pattern&&E(s.FIELD_PATTERN_IN_USE,q({method:"addField"},t)),t.pattern,t.type;var r=function(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(t,["pattern","type"]);return this[l[t.type]](e,r)}return this.otherFields[t.type]||(this.otherFields=z(q({},this.otherFields),{[t.type]:new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:t})})),this._addField(e,this.otherFields[t.type])}addThreeDSecure(e,t){this.threeDS||(this.threeDS=new L(this),this.threeDS.init(e,t))}addClickToPay(e,t){return(r=function*(){if(!this.paymentMethodId)return this.clickToPayInstance=yield new K(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"})},function(){var e=this,t=arguments;return new Promise((function(n,i){var o=r.apply(e,t);function a(e){W(o,n,i,a,s,"next",e)}function s(e){W(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var r}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===V?"".concat(r,":"):"").concat(e);p.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===V?"".concat(r,":"):"").concat(e);p.unsubscribe(n,t)}submit(){var e,t,r=e=>{var t,n=[this.frameUrl,null===(t=this.clickToPayInstance)||void 0===t?void 0:t.origin].includes(e.origin),o=e.data.channel===c,a=["success","error"].includes(e.data.type);if(n&&o&&a){switch(e.data.type){case"success":var s;p.publish(i.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(E(e.data.data.warn),delete e.data.data.warn),C("Payment method tokenized successfully",e.data.data);break;case"error":p.publish(i.CARD_VAULT_FAILURE,e.data),C("Failed to update checkout session",e.data.data)}window.removeEventListener("message",r)}};window.addEventListener("message",r),"click-to-pay"===this.method||"card"===this.method&&(null===(e=this.clickToPayInstance)||void 0===e?void 0:e.controller)&&!0===(null===(t=this.clickToPayInstance)||void 0===t?void 0:t.consent)?this.clickToPayInstance.controller.contentWindow.postMessage({type:"submit",channel:c},this.clickToPayInstance.url):this.controller.contentWindow.postMessage({type:"submit",channel:c,data:{method:this.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(n,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){var t,n;B(this,"config",void 0),B(this,"controller",void 0),B(this,"frameUrl",void 0),B(this,"apiUrl",void 0),B(this,"parentOrigin",void 0),B(this,"font",void 0),B(this,"cardNumber",void 0),B(this,"securityCode",void 0),B(this,"expiryDate",void 0),B(this,"otherFields",{}),B(this,"method","card"),B(this,"clickToPayInstance",void 0),B(this,"clickToPay",void 0),B(this,"threeDS",void 0),B(this,"environmentPath",void 0),B(this,"paymentMethodId",void 0),p.unsubscribeAll(),this.config=q({environment:"production"},e),this.config.paymentMethodId&&!this.config.paymentMethod&&E(s.PAYMENT_METHOD_ID_DEPRECATED),this.environmentPath="sandbox"===this.config.environment?"sandbox.":"",this.frameUrl=window.SECURE_FIELDS_FRAME_URL||"https://secure-fields.".concat(this.environmentPath).concat(this.config.gr4vyId,".gr4vy.app"),this.parentOrigin=window.location.origin,this.paymentMethodId=(null===(t=this.config.paymentMethod)||void 0===t?void 0:t.id)||this.config.paymentMethodId;var o=q({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{});null===(n=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===n||n.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=r("".concat(this.frameUrl,"/controller.html"),o),this.controller.title="Secure Controller",this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.paymentMethodId&&(this.cardNumber=new V,this.expiryDate=new V),C("Initialized",z(q({},this.config),{version:Z.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var a=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=q({version:Z.version},this.config);p.publish(i.READY,t),C("Ready",t);break;case"form-change":p.publish(i.FORM_CHANGE,e.data.data),C("Form change",e.data.data)}};f.remove("message",a,"init"),f.add("message",a,"init")}}return t})()));
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Events:()=>i,SecureFields:()=>Z,SecureInput:()=>V});var r=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()),n="@gr4vy-secure-fields-debug",i=function(e){return e.CARD_VAULT_SUCCESS="card-vault-success",e.CARD_VAULT_FAILURE="card-vault-failure",e.FORM_CHANGE="form-change",e.METHOD_CHANGE="method-change",e.READY="ready",e.RESIZE="resize",e.CLICK_TO_PAY_INITIALIZED="click-to-pay-initialized",e.CLICK_TO_PAY_READY="click-to-pay-ready",e.CLICK_TO_PAY_SIGN_OUT="click-to-pay-sign-out",e.CLICK_TO_PAY_ERROR="click-to-pay-error",e.CLICK_TO_PAY_CANCEL="click-to-pay-cancel",e.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD="click-to-pay-checkout-with-new-card",e.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA="click-to-pay-unable-to-load-dpa",e.CLICK_TO_PAY_VISIBILITY_CHANGE="click-to-pay:visibility-change",e.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE="click-to-pay-card-form:visibility-change",e.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE="click-to-pay-sign-in:visibility-change",e.CLICK_TO_PAY_PROCESSING="click-to-pay-processing",e.CLICK_TO_PAY_AUTHENTICATE="click-to-pay-authenticate",e.CLICK_TO_PAY_AUTHENTICATE_FAILURE="click-to-pay-authenticate-failure",e.THREE_DS_START="three-ds-start",e.THREE_DS_FINISH="three-ds-finish",e}({}),o=function(e){return e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port",e.REQUEST_RECOGNITION_TOKEN="request-recognition-token",e.REQUEST_RECOGNITION_TOKEN_FAILED="request-recognition-token-failed",e.RECOGNITION_TOKEN="recognition-token",e}({}),a=function(e){return e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled",e}({}),s=function(e){return e.PAYMENT_METHOD_ID_IN_USE="You're passing a paymentMethodId to use a stored payment method, which means Secure Fields methods `addCardNumber`, `addExpiryDate` and `addClickToPay` are automatically disabled and won't render the related fields",e.PAYMENT_METHOD_ID_DEPRECATED="The 'paymentMethodId' prop is deprecated and will be removed in a future version. Please use the 'paymentMethod' prop instead: { paymentMethod: { id: 'your-id', scheme: 'visa' } }",e.FIELD_PATTERN_IN_USE="The `pattern` option can't be used on card fields, so it won't be applied here.",e.NO_RECOGNITION_TOKEN="The recognition token couldn't be obtained or the request took too much time. It is possible that a Click to Pay user was therefore not recognised.",e}({}),c="secure-fields",l={number:"addCardNumberField",expiryDate:"addExpiryDateField",securityCode:"addSecurityCodeField"},d=["01","02","03","04","05"];function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return u(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?u(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var p=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=h(r,2),i=n[0],o=n[1];return i!==e||o.toString()!==t.toString()}))}unsubscribeAll(){this.subscribers=[]}publish(e,t){this.subscribers.forEach((r=>{var n=h(r,2),i=n[0],o=n[1];return setTimeout((()=>i===e?o(t):null),0)}))}constructor(){var e,t;t=void 0,(e="subscribers")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t,this.subscribers=[]}};function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(e,t)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var f=new class{add(e,t,r){window.addEventListener(e,t),this.listeners.push([e,t,r])}remove(e,t,r){var n=this.listeners.findIndex((n=>{var i=m(n,3),o=i[0],a=i[1],s=i[2];return o===e&&a.toString()===t.toString()&&s===r}));if(-1!==n){var i=m(this.listeners.splice(n,1),1),o=m(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=m(e,2),r=t[0],n=t[1];window.removeEventListener(r,n)})),this.listeners=[]}constructor(){var e,t;t=[],(e="listeners")in this?Object.defineProperty(this,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):this[e]=t}},b=e=>{var t,r;if(null===(t=document)||void 0===t?void 0:t.cookie)return null===(r="; ".concat(document.cookie).match(";\\s*".concat(e,"=([^;]+)")))||void 0===r?void 0:r[1]},v=["accesskey","autocapitalize","autocomplete","autofocus","aria-.","class","contenteditable","data-.","dir","draggable","enterkeyhint","hidden","id","inert","inputmode","is","itemid","itemprop","itemref","itemscope","itemtype","lang","nonce","onabort","onautocomplete","onautocompleteerror","onblur","oncancel","oncanplay","oncanplaythrough","onchange","onclick","onclose","oncontextmenu","oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","ondurationchange","onemptied","onended","onerror","onfocus","oninput","oninvalid","onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown","onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onmousewheel","onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onseeked","onseeking","onselect","onshow","onsort","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle","onvolumechange","onwaiting","popover","role","slot","spellcheck","style","tabindex","title","translate"],_=(e,t)=>e&&(e.style.display=t?"block":"none");function I(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function g(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){I(e,t,r[t])}))}return e}var O={debug:!1,level:"log"},C=(e,t,r)=>{var i=g({},O,r),o=i.debug,a=i.level;(o||"true"===localStorage.getItem(n))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},E=(e,t,r)=>{var n,i;C(e,t,(n=g({},r),i=null!=(i={level:"warn"})?i:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(i)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})),n))},T=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var P=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,i)=>{var o,a,s=(a=2,function(e){if(Array.isArray(e))return e}(o=i)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);a=!0);}catch(e){s=!0,i=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw i}}return o}}(o,a)||function(e,t){if(e){if("string"==typeof e)return A(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?A(e,t):void 0}}(o,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),c=s[0],l=s[1];return(e=>"[object Object]"===Object.prototype.toString.call(e))(l)?n.push(...e(t[c],"".concat((r+c).match(/[a-zA-Z0-9]+/g).join("-"),"-"))):(c=T(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function S(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function w(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function N(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){w(e,t,r[t])}))}return e}function k(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class L{init(e,t){var n;this.challengeWindowSize=d.includes(null==t?void 0:t.challengeWindowSize)?t.challengeWindowSize:"05",this.element="string"==typeof e?document.querySelector(e):e;var i="gr4vy-threeds-flow-controller";null===(n=document.body.querySelector("iframe#".concat(i)))||void 0===n||n.remove();var o=document.createElement("iframe");o.id=i,o.title="ThreeDSecure",o.style.display="block",o.style.border="0px",o.style.padding="0px",o.style.margin="0px",o.style.width="100%",o.style.height="100%",o.src=r(this.secureFields.frameUrl+"/threeds.html",{sessionId:this.secureFields.config.sessionId,parentOrigin:this.secureFields.parentOrigin,gr4vyId:this.secureFields.config.gr4vyId,environment:this.secureFields.config.environment}),this.element.appendChild(o),this.controller=o;var a={type:"three-ds-init",channel:c,data:{challengeWindowSize:this.challengeWindowSize}};return o.addEventListener("load",(()=>{var e;null===(e=o.contentWindow)||void 0===e||e.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),this.secureFields.controller.addEventListener("load",(()=>{this.secureFields.controller.contentWindow.postMessage(a,this.secureFields.frameUrl)}),{once:!0}),f.remove("message",this.listener.bind(this),"three-ds"),f.add("message",this.listener.bind(this),"three-ds"),this}listener(e){return(t=function*(){if(e.origin===this.secureFields.frameUrl){var t=e.data,r=t.type,n=t.data;switch(r){case i.THREE_DS_START:p.publish(i.THREE_DS_START,k(N({},n),{element:this.element})),C("3DS start",e.data.data);break;case i.THREE_DS_FINISH:p.publish(i.THREE_DS_FINISH,k(N({},n),{element:this.element})),C("3DS finish",e.data.data)}}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){S(o,n,i,a,s,"next",e)}function s(e){S(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}constructor(e){w(this,"secureFields",void 0),w(this,"controller",void 0),w(this,"challengeWindowSize",void 0),w(this,"element",void 0),this.secureFields=e}}function D(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}class R extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function j(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function U(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){j(o,n,i,a,s,"next",e)}function s(e){j(o,n,i,a,s,"throw",e)}a(void 0)}))}}function M(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(){return F=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},F.apply(this,arguments)}function Y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){M(e,t,r[t])}))}return e}class K{_addIframe(e,t,n,i){var o=document.createElement("iframe");return o.id=e,o.title=t,o.setAttribute("width","100%"),o.setAttribute("frameborder","0"),o.setAttribute("style","height:0px"),o.src=r(n,i),o}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,a=r.data,l=a.type,d=a.data;switch(n){case this.origin:switch(l){case i.RESIZE:this.controller.style.height="".concat(d.height>0?d.height+48:0,"px");break;case i.METHOD_CHANGE:var u=d.method||"card";(this.secureFields.method!==u||t)&&(t=!1,this.secureFields.updateMethod(u,{data:d}),_(this.cardForm,"card"===u),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===u));break;case i.CLICK_TO_PAY_INITIALIZED:p.publish(i.CLICK_TO_PAY_INITIALIZED,this.clickToPay),C("Click to Pay initialized",this.clickToPay),_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),_(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_READY:this._buyerExists=d.buyerExists,p.publish(i.CLICK_TO_PAY_READY,d),C("Click to Pay ready"),_(this.signIn,!d.buyerExists),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!d.buyerExists),_(this.clickToPay.element,!0),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case i.CLICK_TO_PAY_SIGN_OUT:this.clickToPay.signOut();break;case i.CLICK_TO_PAY_ERROR:p.publish(i.CLICK_TO_PAY_ERROR,d),C("Click to Pay error:",d),_(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),_(this.clickToPay.element,"UNKNOWN"!==d.error),p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==d.error);break;case i.CLICK_TO_PAY_CANCEL:p.publish(i.CLICK_TO_PAY_CANCEL,d),C("Click to Pay cancelled"),this._buyerExists||(_(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:p.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,d),_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),C("Click to Pay checkout with new card initiated");break;case i.CLICK_TO_PAY_PROCESSING:_(this.cardForm,!d),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,d),C("Click to Pay processing",d);break;case i.CLICK_TO_PAY_AUTHENTICATE:!function(e,t){for(var r=arguments.length,n=new Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];document.cookie="".concat(e,"=").concat(t,"; path=/; ").concat(n.join("; "))}("recognitionToken",d.recognitionToken,"Secure","SameSite=Strict","MaxAge=15552000");break;case i.CLICK_TO_PAY_AUTHENTICATE_FAILURE:p.publish(i.CLICK_TO_PAY_AUTHENTICATE_FAILURE,d),C("Click to Pay authenticate failure:",d);break;case o.REQUEST_RECOGNITION_TOKEN:this.controller.contentWindow.postMessage({channel:c,type:o.RECOGNITION_TOKEN,data:{recognitionToken:b("recognitionToken")}},this.origin);break;case o.REQUEST_RECOGNITION_TOKEN_FAILED:E(s.NO_RECOGNITION_TOKEN);break;case o.REQUEST_PORT:this.controller.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.origin,[e.port1])}break;case this.secureFields.frameUrl:l===o.REQUEST_PORT&&this.encrypt.contentWindow.postMessage({channel:c,type:o.TRANSFER_PORT},this.secureFields.frameUrl,[e.port2])}};f.remove("message",r,"click-to-pay"),f.add("message",r,"click-to-pay")}_fetchDPA(e,t){return U((function*(e,t){var r=t.gr4vyId,n=t.environment,o=t.sessionId;try{var a=e||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(r,n);return yield function(e){return(t=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var n="".concat(t,"/digital-wallets/click-to-pay/session"),i=yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(i.ok){var o=yield i.json();return{srcDpaId:o.digital_payment_application_id,dpaName:o.digital_payment_application_name}}throw new R("Unable to load DPA")}catch(e){throw new R("Unable to load DPA")}},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){D(o,n,i,a,s,"next",e)}function s(e){D(o,n,i,a,s,"throw",e)}a(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:a,checkoutSessionId:o})}catch(e){return C(e.message),p.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),_(this.cardForm,!0),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),_(this.clickToPay.element,!1),void p.publish(i.CLICK_TO_PAY_VISIBILITY_CHANGE,!1)}})).apply(this,arguments)}_initConsentCheckbox(e){var t=e.checked?"click-to-pay":"card";this.secureFields.updateMethod(t,{data:{method:t}}),e.addEventListener("change",(e=>{var t=e.target;this.consent=t.checked})),f.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this.consent=!1,e.checked=!1);break;case i.METHOD_CHANGE:var r=this._buyerExists&&"card"===t.data.data.method;this.consent=r,e.checked=r}}),"click-to-pay-consent-checkbox")}_setNewCardRememberMe(e){this.controller.contentWindow.postMessage({type:"remember-me-new-card-changed",channel:c,data:{value:e}},this.origin)}_initNewCardRememberMeCheckbox(e){e.addEventListener("change",(e=>{var t=e.target;this._setNewCardRememberMe(t.checked)})),f.add("message",(t=>{switch(t.data.type){case i.CLICK_TO_PAY_INITIALIZED:this._setNewCardRememberMe(e.checked);break;case i.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this._setNewCardRememberMe(!1),e.checked=!1)}}),"click-to-pay-new-card-remember-me-checkbox")}_initLearnMore(e){e.style.visibility="hidden",f.add("message",(t=>{t.data.type===i.CLICK_TO_PAY_INITIALIZED&&(e.style.visibility="visible",e.addEventListener("click",(()=>{this.controller.contentWindow.postMessage({type:"show-learn-more",channel:c},this.origin)})))}),"click-to-pay-learn-more")}init(e,t){return U((function*(){this.cardForm="string"==typeof(null==t?void 0:t.cardForm)?document.querySelector(null==t?void 0:t.cardForm):null==t?void 0:t.cardForm,this.signIn="string"==typeof(null==t?void 0:t.signIn)?document.querySelector(null==t?void 0:t.signIn):null==t?void 0:t.signIn,_(this.signIn,!1);var r=this.secureFields,n=r.apiUrl,o=r.config,a=o.gr4vyId,s=o.environment,c=o.sessionId,l=r.environmentPath;if(this.clickToPay={element:null,options:t,signIn:e=>{var t=e.email,r=e.mobileNumber;return U((function*(){var e=this.clickToPay,n=e.element,o=e.options;delete o.email,delete o.mobileNumber,n.innerHTML="",_(this.signIn,!1),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),_(this.cardForm,!1),p.publish(i.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),this.secureFields.update("clickToPay",yield this.init(n,Y({},o,t?{email:t}:{},r?{mobileNumber:r}:{})))})).call(this)},signOut:()=>(this._buyerExists=!1,p.publish(i.CLICK_TO_PAY_SIGN_OUT),C("Click to pay signed out"),_(this.signIn,!0),p.publish(i.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0),document.cookie="".concat("recognitionToken","=; path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC;"),this.clickToPay.signIn({email:null,mobileNumber:null}))},!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName)){var d=yield this._fetchDPA(n,{gr4vyId:a,environment:s,sessionId:c});if(!(null==d?void 0:d.srcDpaId)&&!(null==d?void 0:d.dpaName))return;t.srcDpaId=d.srcDpaId,t.dpaName=d.dpaName}this.url=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(l).concat(a,".gr4vy.app"),this.origin=new URL(this.url).origin;var u=window.location.origin,h=(function(e){if(null==e)throw new TypeError("Cannot destructure "+e)}(t),Y({gr4vyId:a,environment:s,sessionId:c},F({},t)));if(this.controller=this._addIframe("click-to-pay-controller","Click To Pay","".concat(this.url,"/click-to-pay.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this.encrypt=this._addIframe("click-to-pay-encrypt","Click To Pay Encrypt","".concat(this.secureFields.frameUrl,"/click-to-pay-encrypt.html"),{parentOrigin:u,environment:s,config:encodeURIComponent(JSON.stringify(h))}),this._attachListeners(),null==t?void 0:t.consentCheckbox){var y="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;y&&this._initConsentCheckbox(y)}if(null==t?void 0:t.rememberMeCheckbox){var m="string"==typeof(null==t?void 0:t.rememberMeCheckbox)?document.querySelector(t.rememberMeCheckbox):null==t?void 0:t.rememberMeCheckbox;m&&this._initNewCardRememberMeCheckbox(m)}if(null==t?void 0:t.learnMoreLink){var f="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;f&&this._initLearnMore(f)}return(e="string"==typeof e?document.querySelector(e):e).appendChild(this.controller),e.appendChild(this.encrypt),this.clickToPay.element=e,this.clickToPay})).call(this)}constructor(e){M(this,"secureFields",void 0),M(this,"_buyerExists",void 0),M(this,"consent",void 0),M(this,"controller",void 0),M(this,"encrypt",void 0),M(this,"origin",void 0),M(this,"url",void 0),M(this,"cardForm",void 0),M(this,"signIn",void 0),M(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}function x(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function H(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){x(e,t,r[t])}))}return e}function G(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class V{_postMessage(e){this.frame.contentWindow.postMessage(H({channel:c},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=H({},this.options,e);var t=P(H({},this.options.styles,e.styles)),r=G(H({},this.options,e),{styles:t});this._postMessage({type:"update",data:G(H({},r),{styles:t})}),C("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}clear(){if(this.frameUrl){var e=this.type;this._postMessage({type:"reset",data:{type:e}}),C("Cleared field",{type:e})}}constructor(e){if(x(this,"frameUrl",void 0),x(this,"parentOrigin",void 0),x(this,"frame",void 0),x(this,"type",void 0),x(this,"options",void 0),x(this,"addEventListener",void 0),x(this,"removeEventListener",void 0),e){var t=e.frameUrl,r=e.parentOrigin,n=e.font,i=e.options,o=i.type,a=function(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(i,["type"]),s=e.paymentMethodScheme;this.frameUrl=t,this.parentOrigin=r,this.type=o,this.options=a;var c=P(a.styles);this.frame=document.createElement("iframe"),this.frame.id=o,this.frame.src="".concat(t,"/input.html?parentOrigin=").concat(r,"&type=").concat(this.type),this.frame.title="Secure Input",this.frame.style.display="block",this.frame.style.height="100%",this.frame.style.border="none",this.frame.style.width="100%",n&&(this.frame.src+="&font=".concat(n)),s&&(this.frame.src+="&paymentMethodScheme=".concat(s)),this.frame.onload=()=>{this._postMessage({type:"update",data:G(H({},this.options),{styles:c,type:o})}),C("Added field",this.options)}}}}function W(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function B(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function q(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){B(e,t,r[t])}))}return e}function z(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class Z{static get Events(){return i}static get version(){return"#77df1f6ab357ffefaebc2975dee7409167a37548"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),p.publish(i.METHOD_CHANGE,r),C("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:c},this.frameUrl)}_addField(e,t){var r;if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var n,i,o=document.createElement("div");n=e,i=o,Array.from(n.attributes).forEach((e=>{var t=e.name,r=e.value;v.some((e=>new RegExp(e).test(t)))&&i.setAttribute(t,r)})),(o=i).classList.add("secure-fields__input","secure-fields__input--".concat(T(t.type))),o.appendChild(t.frame),null===(r=e.parentNode)||void 0===r||r.replaceChild(o,e);var s=e=>{var r;if(e.origin===this.frameUrl&&(null===(r=e.data.data)||void 0===r?void 0:r.id)===t.type)switch(e.data.type){case"blur":p.publish("".concat(t.type,":blur"),e.data.data),o.removeAttribute(a.FOCUSED),C("Field blurred",e.data.data);break;case"focus":p.publish("".concat(t.type,":focus"),e.data.data),o.setAttribute(a.FOCUSED,""),C("Field focused",e.data.data);break;case"input":p.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?o.removeAttribute(a.INVALID):o.setAttribute(a.INVALID,""),e.data.data.autofilled?o.setAttribute(a.AUTOFILLED,""):o.removeAttribute(a.AUTOFILLED),C("Field input changed",e.data.data)}};return f.remove("message",s,t.type),f.add("message",s,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.paymentMethodId&&E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:z(q({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){var r,n;return this.securityCode||(this.securityCode=new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:z(q({label:"Security code"},this.paymentMethodId&&!(null===(r=this.config.paymentMethod)||void 0===r?void 0:r.scheme)?{lengths:[3,4]}:{},t),{type:"securityCode"}),paymentMethodScheme:null===(n=this.config.paymentMethod)||void 0===n?void 0:n.scheme})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.paymentMethodId&&E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:z(q({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addField(e,t){if(["number","expiryDate","securityCode"].includes(t.type)){t.pattern&&E(s.FIELD_PATTERN_IN_USE,q({method:"addField"},t)),t.pattern,t.type;var r=function(e,t){if(null==e)return{};var r,n,i,o={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(r=Reflect.ownKeys(Object(e)),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}if(o=function(e,t){if(null==e)return{};var r,n,i={},o=Object.getOwnPropertyNames(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}(e,t),Object.getOwnPropertySymbols)for(r=Object.getOwnPropertySymbols(e),i=0;i<r.length;i++)n=r[i],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(t,["pattern","type"]);return this[l[t.type]](e,r)}return this.otherFields[t.type]||(this.otherFields=z(q({},this.otherFields),{[t.type]:new V({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:t})})),this._addField(e,this.otherFields[t.type])}addThreeDSecure(e,t){this.threeDS||(this.threeDS=new L(this),this.threeDS.init(e,t))}addClickToPay(e,t){return(r=function*(){if(!this.paymentMethodId)return this.clickToPayInstance=yield new K(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;E(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"})},function(){var e=this,t=arguments;return new Promise((function(n,i){var o=r.apply(e,t);function a(e){W(o,n,i,a,s,"next",e)}function s(e){W(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var r}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===V?"".concat(r,":"):"").concat(e);p.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===V?"".concat(r,":"):"").concat(e);p.unsubscribe(n,t)}submit(){var e,t,r=e=>{var t,n=[this.frameUrl,null===(t=this.clickToPayInstance)||void 0===t?void 0:t.origin].includes(e.origin),o=e.data.channel===c,a=["success","error"].includes(e.data.type);if(n&&o&&a){switch(e.data.type){case"success":var s;p.publish(i.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(E(e.data.data.warn),delete e.data.data.warn),C("Payment method tokenized successfully",e.data.data);break;case"error":p.publish(i.CARD_VAULT_FAILURE,e.data),C("Failed to update checkout session",e.data.data)}window.removeEventListener("message",r)}};window.addEventListener("message",r),"click-to-pay"===this.method||"card"===this.method&&(null===(e=this.clickToPayInstance)||void 0===e?void 0:e.controller)&&!0===(null===(t=this.clickToPayInstance)||void 0===t?void 0:t.consent)?this.clickToPayInstance.controller.contentWindow.postMessage({type:"submit",channel:c},this.clickToPayInstance.url):this.controller.contentWindow.postMessage({type:"submit",channel:c,data:{method:this.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(n,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){var t,n;B(this,"config",void 0),B(this,"controller",void 0),B(this,"frameUrl",void 0),B(this,"apiUrl",void 0),B(this,"parentOrigin",void 0),B(this,"font",void 0),B(this,"cardNumber",void 0),B(this,"securityCode",void 0),B(this,"expiryDate",void 0),B(this,"otherFields",{}),B(this,"method","card"),B(this,"clickToPayInstance",void 0),B(this,"clickToPay",void 0),B(this,"threeDS",void 0),B(this,"environmentPath",void 0),B(this,"paymentMethodId",void 0),p.unsubscribeAll(),this.config=q({environment:"production"},e),this.config.paymentMethodId&&!this.config.paymentMethod&&E(s.PAYMENT_METHOD_ID_DEPRECATED),this.environmentPath="sandbox"===this.config.environment?"sandbox.":"",this.frameUrl=window.SECURE_FIELDS_FRAME_URL||"https://secure-fields.".concat(this.environmentPath).concat(this.config.gr4vyId,".gr4vy.app"),this.parentOrigin=window.location.origin,this.paymentMethodId=(null===(t=this.config.paymentMethod)||void 0===t?void 0:t.id)||this.config.paymentMethodId;var o=q({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{});null===(n=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===n||n.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=r("".concat(this.frameUrl,"/controller.html"),o),this.controller.title="Secure Controller",this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.paymentMethodId&&(this.cardNumber=new V,this.expiryDate=new V),C("Initialized",z(q({},this.config),{version:Z.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var a=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=q({version:Z.version},this.config);p.publish(i.READY,t),C("Ready",t);break;case"form-change":p.publish(i.FORM_CHANGE,e.data.data),C("Form change",e.data.data)}};f.remove("message",a,"init"),f.add("message",a,"init")}}return t})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gr4vy/secure-fields",
|
|
3
|
-
"version": "2.3.0
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Gr4vy-hosted secure fields offering advanced theming, PCI compliance, event handling, and more.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"types": "lib/index",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"css-loader": "^6.11.0",
|
|
46
46
|
"csstype": "^3.2.3",
|
|
47
47
|
"dotenv": "^16.6.1",
|
|
48
|
-
"msw": "^2.12.
|
|
48
|
+
"msw": "^2.12.11",
|
|
49
49
|
"style-loader": "^3.3.4",
|
|
50
50
|
"ts-patch": "^3.3.0",
|
|
51
51
|
"typedoc": "^0.28.17",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"access": "public",
|
|
57
57
|
"registry": "https://registry.npmjs.org"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "77df1f6ab357ffefaebc2975dee7409167a37548"
|
|
60
60
|
}
|