@gr4vy/secure-fields 1.23.0 → 2.0.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 CHANGED
@@ -1,3 +1,50 @@
1
+ # v2.0.0 (Mon Sep 08 2025)
2
+
3
+ #### 💥 Breaking Change
4
+
5
+ - task: postal code field [#959](https://github.com/gr4vy/secure-fields/pull/959) ([@luca-gr4vy](https://github.com/luca-gr4vy))
6
+ - task: add postal code field [#950](https://github.com/gr4vy/secure-fields/pull/950) ([@luca-gr4vy](https://github.com/luca-gr4vy))
7
+
8
+ #### 🐛 Bug Fix
9
+
10
+ - Revert "task: add postal code field" [#956](https://github.com/gr4vy/secure-fields/pull/956) ([@gryevns](https://github.com/gryevns))
11
+
12
+ #### 🏠 Internal
13
+
14
+ - chore(dev-deps): update dependency typedoc to ^0.28.12 [#964](https://github.com/gr4vy/secure-fields/pull/964) ([@renovate[bot]](https://github.com/renovate[bot]))
15
+ - chore(dev-deps): update dependency typedoc to ^0.28.10 [#948](https://github.com/gr4vy/secure-fields/pull/948) ([@renovate[bot]](https://github.com/renovate[bot]) [@luca-gr4vy](https://github.com/luca-gr4vy))
16
+
17
+ #### Authors: 3
18
+
19
+ - [@renovate[bot]](https://github.com/renovate[bot])
20
+ - Gary Evans ([@gryevns](https://github.com/gryevns))
21
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
22
+
23
+ ---
24
+
25
+ # v1.24.0 (Thu Jul 31 2025)
26
+
27
+ #### 🚀 Enhancement
28
+
29
+ - feat(stored-payment-method): add scheme-based CVV validation [#934](https://github.com/gr4vy/secure-fields/pull/934) ([@brunodesde1987](https://github.com/brunodesde1987) [@luca-gr4vy](https://github.com/luca-gr4vy))
30
+
31
+ #### 🐛 Bug Fix
32
+
33
+ - chore: replace gr4vy node with gr4vy sdk [#935](https://github.com/gr4vy/secure-fields/pull/935) ([@luca-gr4vy](https://github.com/luca-gr4vy))
34
+
35
+ #### 🏠 Internal
36
+
37
+ - chore(dev-deps): update dependency dotenv to ^16.6.1 [#932](https://github.com/gr4vy/secure-fields/pull/932) ([@renovate[bot]](https://github.com/renovate[bot]))
38
+ - chore(dev-deps): update dependency typedoc to ^0.28.7 [#923](https://github.com/gr4vy/secure-fields/pull/923) ([@renovate[bot]](https://github.com/renovate[bot]))
39
+
40
+ #### Authors: 3
41
+
42
+ - [@renovate[bot]](https://github.com/renovate[bot])
43
+ - Bruno Carvalho ([@brunodesde1987](https://github.com/brunodesde1987))
44
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
45
+
46
+ ---
47
+
1
48
  # v1.23.0 (Thu Jun 12 2025)
2
49
 
3
50
  #### 🐛 Bug Fix
package/README.md CHANGED
@@ -34,7 +34,7 @@ To use Secure Fields, you need some placeholder elements to attach the secure fi
34
34
  <button id="cc-button">Submit</button>
35
35
  ```
36
36
 
37
- To use Secure Fields, call the `new SecureFields()` method with a configuration object that includes the `environment` (`sandbox` or `production`), your `gr4vyId` and a `sessionId` obtained from calling the [Checkout Sessions API](https://gr4vy.com/docs/reference#tag/Checkout-Sessions). An optional `paymentMethodId` parameter can also be passed to use Secure Fields with a stored payment method.
37
+ To use Secure Fields, call the `new SecureFields()` method with a configuration object that includes the `environment` (`sandbox` or `production`), your `gr4vyId` and a `sessionId` obtained from calling the [Checkout Sessions API](https://gr4vy.com/docs/reference#tag/Checkout-Sessions). An optional `paymentMethod` object with `id` and `scheme` can also be passed to use Secure Fields with a stored payment method.
38
38
 
39
39
  Then, add the fields and event listeners needed to handle the form submission.
40
40
 
@@ -48,7 +48,15 @@ const secureFields = new SecureFields({
48
48
  gr4vyId: '[GR4VY_ID]',
49
49
  environment: 'sandbox',
50
50
  sessionId: '[SESSION_ID]',
51
- // paymentMethodId: '[PAYMENT_METHOD_ID]', // uuid of a stored payment method (optional)
51
+
52
+ // For stored payment methods (optional):
53
+ // paymentMethod: {
54
+ // id: '[PAYMENT_METHOD_ID]',
55
+ // scheme: 'visa' // Enables accurate CVV validation (3 digits for Visa/Mastercard, 4 for Amex)
56
+ // },
57
+
58
+ // Deprecated:
59
+ // paymentMethodId: '[PAYMENT_METHOD_ID]', // uuid of a stored payment method
52
60
  })
53
61
 
54
62
  secureFields.addFont('Lato')
@@ -326,7 +334,7 @@ The following Click to Pay events can be listened to by attaching an event handl
326
334
 
327
335
  | Name | Description |
328
336
  | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
329
- | `constructor` | Instantiates SecureFields with a configuration object include `environment`, `gr4vyId` and a session id. An optional `paymentMethodId` parameter can also be passed to use Secure Fields with a stored payment method. <br /><br />`new SecureFields({...})` |
337
+ | `constructor` | Instantiates SecureFields with a configuration object include `environment`, `gr4vyId` and a session id. An optional `paymentMethod` object with `id` and `scheme` can also be passed to use Secure Fields with a stored payment method. <br /><br />`new SecureFields({...})` |
330
338
  | `addCardNumberField` | Injects a secure field of type `number`. <br /><br />`secureFields.addCardNumberField('#cc-number', { placeholder: 'Enter card number', ... })` |
331
339
  | `addSecurityCodeField` | Injects a secure field of type `securityCode`. <br /><br />`secureFields.addSecurityCodeField('#cc-security-code', { placeholder: 'Enter security code', ... })` |
332
340
  | `addExpiryDateField` | Injects a secure field of type `expiryDate`. <br /><br />`secureFields.addExpiryDateField('#cc-expiry-date', { placeholder: 'Enter expiry date', ... })` |
@@ -28,6 +28,7 @@ export declare enum FieldAttributes {
28
28
  AUTOFILLED = "data-secure-fields-autofilled"
29
29
  }
30
30
  export declare enum LogMessages {
31
- 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"
31
+ 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",
32
+ 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' } }"
32
33
  }
33
34
  export declare const MESSAGE_CHANNEL = "secure-fields";
package/lib/index.d.ts CHANGED
@@ -17,10 +17,12 @@ declare class SecureFields {
17
17
  cardNumber: SecureInput;
18
18
  securityCode: SecureInput;
19
19
  expiryDate: SecureInput;
20
+ otherFields: Record<string, SecureInput>;
20
21
  method: 'card' | 'click-to-pay';
21
22
  private clickToPayInstance?;
22
23
  clickToPay?: ClickToPayInstance;
23
24
  environmentPath: string;
25
+ private paymentMethodId?;
24
26
  /**
25
27
  * CARD_VAULT_SUCCESS: Triggered when the card is successfully vaulted.
26
28
  *
@@ -41,6 +43,7 @@ declare class SecureFields {
41
43
  addCardNumberField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
42
44
  addSecurityCodeField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
43
45
  addExpiryDateField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
46
+ addField(element: string | HTMLElement, options: Omit<Field, 'element'>): SecureInput;
44
47
  addClickToPay(element: string | HTMLElement, options?: ClickToPayOptions): Promise<ClickToPayInstance>;
45
48
  addEventListener(event: CombinedEvents, callback: (...args: any[]) => void): void;
46
49
  removeEventListener(event: CombinedEvents, callback: (...args: any[]) => void): void;
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={};function r(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)}e.r(t),e.d(t,{Events:()=>o,SecureFields:()=>x,SecureInput:()=>Y});class n extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}var i="@gr4vy-secure-fields-debug",o=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}({}),a=function(e){return e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port",e}({}),s=function(e){return e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled",e}({}),c=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}({}),l="secure-fields";function d(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 u(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 d(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)?d(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 h=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=u(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=u(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 p(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 y(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 p(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)?p(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=y(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=y(this.listeners.splice(n,1),1),o=y(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=y(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}},m=["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"],b=(e,t)=>e&&(e.style.display=t?"block":"none");function v(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _(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){v(e,t,r[t])}))}return e}var I={debug:!1,level:"log"},g=(e,t,r)=>{var n=_({},I,r),o=n.debug,a=n.level;(o||"true"===localStorage.getItem(i))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},O=(e,t,r)=>{var n,i;g(e,t,(n=_({},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))},C=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=C(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})},E=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString());function T(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 L(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){T(o,n,i,a,s,"next",e)}function s(e){T(o,n,i,a,s,"throw",e)}a(void 0)}))}}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 S(){return S=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},S.apply(this,arguments)}function k(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}class N{_addIframe(e,t,r,n){var i=document.createElement("iframe");return i.id=e,i.title=t,i.setAttribute("width","100%"),i.setAttribute("frameborder","0"),i.setAttribute("style","height:0px"),i.src=E(r,n),i}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,i=r.data,s=i.type,c=i.data;switch(n){case this.origin:switch(s){case o.RESIZE:this.controller.style.height="".concat(c.height>0?c.height+48:0,"px");break;case o.METHOD_CHANGE:var d=c.method||"card";(this.secureFields.method!==d||t)&&(t=!1,this.secureFields.updateMethod(d,{data:c}),b(this.cardForm,"card"===d),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===d));break;case o.CLICK_TO_PAY_INITIALIZED:h.publish(o.CLICK_TO_PAY_INITIALIZED,this.clickToPay),g("Click to Pay initialized",this.clickToPay),b(this.signIn,!1),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),b(this.clickToPay.element,!0),h.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_READY:this._buyerExists=c.buyerExists,h.publish(o.CLICK_TO_PAY_READY,c),g("Click to Pay ready"),b(this.signIn,!c.buyerExists),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!c.buyerExists),b(this.clickToPay.element,!0),h.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_SIGN_OUT:this._buyerExists=!1,this.clickToPay.signOut(),h.publish(o.CLICK_TO_PAY_SIGN_OUT),g("Click to pay signed out"),b(this.signIn,!0),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_ERROR:h.publish(o.CLICK_TO_PAY_ERROR,c),g("Click to Pay error:",c),b(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(c.error)),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(c.error)),b(this.clickToPay.element,"UNKNOWN"!==c.error),h.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==c.error);break;case o.CLICK_TO_PAY_CANCEL:h.publish(o.CLICK_TO_PAY_CANCEL,c),g("Click to Pay cancelled"),this._buyerExists||(b(this.signIn,!0),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:h.publish(o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,c),b(this.signIn,!1),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),g("Click to Pay checkout with new card initiated");break;case o.CLICK_TO_PAY_PROCESSING:b(this.cardForm,!c),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,c),g("Click to Pay processing",c);break;case a.REQUEST_PORT:this.controller.contentWindow.postMessage({channel:l,type:a.TRANSFER_PORT},this.origin,[e.port1])}break;case this.secureFields.frameUrl:s===a.REQUEST_PORT&&this.encrypt.contentWindow.postMessage({channel:l,type:a.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 L((function*(e,t){var i=t.gr4vyId,a=t.environment,s=t.sessionId;try{var c=e||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(i,a);return yield function(e){return(t=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var i="".concat(t,"/digital-wallets/click-to-pay/session"),o=yield fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(o.ok){var a=yield o.json();return{srcDpaId:a.digital_payment_application_id,dpaName:a.digital_payment_application_name}}throw new n("Unable to load DPA")}catch(e){throw new n("Unable to load DPA")}},function(){var e=this,n=arguments;return new Promise((function(i,o){var a=t.apply(e,n);function s(e){r(a,i,o,s,c,"next",e)}function c(e){r(a,i,o,s,c,"throw",e)}s(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:c,checkoutSessionId:s})}catch(e){return g(e.message),h.publish(o.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),b(this.cardForm,!0),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),b(this.clickToPay.element,!1),void h.publish(o.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 o.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this.consent=!1,e.checked=!1);break;case o.METHOD_CHANGE:var r=this._buyerExists&&"card"===t.data.data.method;this.consent=r,e.checked=r}}),"click-to-pay-consent-checkbox")}_initLearnMore(e){e.style.visibility="hidden",f.add("message",(t=>{t.data.type===o.CLICK_TO_PAY_INITIALIZED&&(e.style.visibility="visible",e.addEventListener("click",(()=>{this.controller.contentWindow.postMessage({type:"show-learn-more",channel:l},this.origin)})))}),"click-to-pay-learn-more")}init(e,t){return L((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,b(this.signIn,!1);var r=this.secureFields,n=r.apiUrl,i=r.config,a=i.gr4vyId,s=i.environment,c=i.sessionId,l=r.environmentPath;if(this.clickToPay={element:null,options:t,signIn:e=>{var t=e.email,r=e.mobileNumber;return L((function*(){var e=this.clickToPay,n=e.element,i=e.options;delete i.email,delete i.mobileNumber,n.innerHTML="",b(this.signIn,!1),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),b(this.cardForm,!1),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),this.secureFields.update("clickToPay",yield this.init(n,k({},i,t?{email:t}:{},r?{mobileNumber:r}:{})))})).call(this)},signOut:()=>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,p=k({gr4vyId:a,environment:s,sessionId:c},S({},function(e){if(null==e)throw new TypeError("Cannot destructure "+e);return e}(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(p))}),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(p))}),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.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){w(this,"secureFields",void 0),w(this,"_buyerExists",void 0),w(this,"consent",void 0),w(this,"controller",void 0),w(this,"encrypt",void 0),w(this,"origin",void 0),w(this,"url",void 0),w(this,"cardForm",void 0),w(this,"signIn",void 0),w(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}function D(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function j(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){D(e,t,r[t])}))}return e}function U(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 Y{_postMessage(e){this.frame.contentWindow.postMessage(j({channel:l},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=j({},this.options,e);var t=P(j({},this.options.styles,e.styles)),r=U(j({},this.options,e),{styles:t});this._postMessage({type:"update",data:U(j({},r),{styles:t})}),g("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){if(D(this,"frameUrl",void 0),D(this,"parentOrigin",void 0),D(this,"frame",void 0),D(this,"type",void 0),D(this,"options",void 0),D(this,"addEventListener",void 0),D(this,"removeEventListener",void 0),e){var t=e.frameUrl,r=e.parentOrigin,n=e.font,i=e.options.type,o=function(e,t){if(null==e)return{};var r,n,i=function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(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.options,["type"]);this.frameUrl=t,this.parentOrigin=r,this.type=i,this.options=o;var a=P(o.styles);this.frame=document.createElement("iframe"),this.frame.id=i,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)),this.frame.onload=()=>{this._postMessage({type:"update",data:U(j({},this.options),{styles:a,type:i})}),g("Added field",this.options)}}}}function R(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 F(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function M(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){F(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 x{static get Events(){return o}static get version(){return"#8f78925935318c6e9d20d6146cf3a7369039ac62"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),h.publish(o.METHOD_CHANGE,r),g("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:l},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;m.some((e=>new RegExp(e).test(t)))&&i.setAttribute(t,r)})),(o=i).classList.add("secure-fields__input","secure-fields__input--".concat(C(t.type))),o.appendChild(t.frame),null===(r=e.parentNode)||void 0===r||r.replaceChild(o,e);var a=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":h.publish("".concat(t.type,":blur"),e.data.data),o.removeAttribute(s.FOCUSED),g("Field blurred",e.data.data);break;case"focus":h.publish("".concat(t.type,":focus"),e.data.data),o.setAttribute(s.FOCUSED,""),g("Field focused",e.data.data);break;case"input":h.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?o.removeAttribute(s.INVALID):o.setAttribute(s.INVALID,""),e.data.data.autofilled?o.setAttribute(s.AUTOFILLED,""):o.removeAttribute(s.AUTOFILLED),g("Field input changed",e.data.data)}};return f.remove("message",a,t.type),f.add("message",a,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.config.paymentMethodId&&O(c.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new Y({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:K(M({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){return this.securityCode||(this.securityCode=new Y({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:K(M({label:"Security code"},this.config.paymentMethodId?{lengths:[3,4]}:{},t),{type:"securityCode"})})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.config.paymentMethodId&&O(c.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new Y({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:K(M({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addClickToPay(e,t){return(r=function*(){if(!this.config.paymentMethodId)return this.clickToPayInstance=yield new N(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;O(c.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){R(o,n,i,a,s,"next",e)}function s(e){R(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===Y?"".concat(r,":"):"").concat(e);h.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===Y?"".concat(r,":"):"").concat(e);h.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),i=e.data.channel===l,a=["success","error"].includes(e.data.type);if(n&&i&&a){switch(e.data.type){case"success":var s;h.publish(o.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(O(e.data.data.warn),delete e.data.data.warn),g("Payment method tokenized successfully",e.data.data);break;case"error":h.publish(o.CARD_VAULT_FAILURE,e.data),g("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:l},this.clickToPayInstance.url):this.controller.contentWindow.postMessage({type:"submit",channel:l,data:{method:this.config.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(i,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){var t;F(this,"config",void 0),F(this,"controller",void 0),F(this,"frameUrl",void 0),F(this,"apiUrl",void 0),F(this,"parentOrigin",void 0),F(this,"font",void 0),F(this,"cardNumber",void 0),F(this,"securityCode",void 0),F(this,"expiryDate",void 0),F(this,"method","card"),F(this,"clickToPayInstance",void 0),F(this,"clickToPay",void 0),F(this,"environmentPath",void 0),h.unsubscribeAll(),this.config=M({environment:"production"},e),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;var r=M({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.config.paymentMethodId?{paymentMethodId:this.config.paymentMethodId}:{});null===(t=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===t||t.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=E("".concat(this.frameUrl,"/controller.html"),r),this.controller.title="Secure Controller",this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.config.paymentMethodId&&(this.cardNumber=new Y,this.expiryDate=new Y),g("Initialized",K(M({},this.config),{version:x.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var n=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=M({version:x.version},this.config);h.publish(o.READY,t),g("Ready",t);break;case"form-change":h.publish(o.FORM_CHANGE,e.data.data),g("Form change",e.data.data)}};f.remove("message",n,"init"),f.add("message",n,"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={};function r(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)}e.r(t),e.d(t,{Events:()=>o,SecureFields:()=>x,SecureInput:()=>M});class n extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}var i="@gr4vy-secure-fields-debug",o=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}({}),a=function(e){return e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port",e}({}),s=function(e){return e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled",e}({}),c=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}({}),l="secure-fields";function d(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 u(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 d(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)?d(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 h=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=u(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=u(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 p(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 y(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 p(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)?p(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=y(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=y(this.listeners.splice(n,1),1),o=y(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=y(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}},m=["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"],v=(e,t)=>e&&(e.style.display=t?"block":"none");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 _(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}var I={debug:!1,level:"log"},g=(e,t,r)=>{var n=_({},I,r),o=n.debug,a=n.level;(o||"true"===localStorage.getItem(i))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},O=(e,t,r)=>{var n,i;g(e,t,(n=_({},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))},C=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=C(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})},E=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString());function T(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){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){T(o,n,i,a,s,"next",e)}function s(e){T(o,n,i,a,s,"throw",e)}a(void 0)}))}}function S(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function L(){return L=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},L.apply(this,arguments)}function k(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){S(e,t,r[t])}))}return e}class N{_addIframe(e,t,r,n){var i=document.createElement("iframe");return i.id=e,i.title=t,i.setAttribute("width","100%"),i.setAttribute("frameborder","0"),i.setAttribute("style","height:0px"),i.src=E(r,n),i}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,i=r.data,s=i.type,c=i.data;switch(n){case this.origin:switch(s){case o.RESIZE:this.controller.style.height="".concat(c.height>0?c.height+48:0,"px");break;case o.METHOD_CHANGE:var d=c.method||"card";(this.secureFields.method!==d||t)&&(t=!1,this.secureFields.updateMethod(d,{data:c}),v(this.cardForm,"card"===d),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===d));break;case o.CLICK_TO_PAY_INITIALIZED:h.publish(o.CLICK_TO_PAY_INITIALIZED,this.clickToPay),g("Click to Pay initialized",this.clickToPay),v(this.signIn,!1),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),v(this.clickToPay.element,!0),h.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_READY:this._buyerExists=c.buyerExists,h.publish(o.CLICK_TO_PAY_READY,c),g("Click to Pay ready"),v(this.signIn,!c.buyerExists),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!c.buyerExists),v(this.clickToPay.element,!0),h.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_SIGN_OUT:this._buyerExists=!1,this.clickToPay.signOut(),h.publish(o.CLICK_TO_PAY_SIGN_OUT),g("Click to pay signed out"),v(this.signIn,!0),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_ERROR:h.publish(o.CLICK_TO_PAY_ERROR,c),g("Click to Pay error:",c),v(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(c.error)),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(c.error)),v(this.clickToPay.element,"UNKNOWN"!==c.error),h.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==c.error);break;case o.CLICK_TO_PAY_CANCEL:h.publish(o.CLICK_TO_PAY_CANCEL,c),g("Click to Pay cancelled"),this._buyerExists||(v(this.signIn,!0),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:h.publish(o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,c),v(this.signIn,!1),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),g("Click to Pay checkout with new card initiated");break;case o.CLICK_TO_PAY_PROCESSING:v(this.cardForm,!c),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,c),g("Click to Pay processing",c);break;case a.REQUEST_PORT:this.controller.contentWindow.postMessage({channel:l,type:a.TRANSFER_PORT},this.origin,[e.port1])}break;case this.secureFields.frameUrl:s===a.REQUEST_PORT&&this.encrypt.contentWindow.postMessage({channel:l,type:a.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 w((function*(e,t){var i=t.gr4vyId,a=t.environment,s=t.sessionId;try{var c=e||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(i,a);return yield function(e){return(t=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var i="".concat(t,"/digital-wallets/click-to-pay/session"),o=yield fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(o.ok){var a=yield o.json();return{srcDpaId:a.digital_payment_application_id,dpaName:a.digital_payment_application_name}}throw new n("Unable to load DPA")}catch(e){throw new n("Unable to load DPA")}},function(){var e=this,n=arguments;return new Promise((function(i,o){var a=t.apply(e,n);function s(e){r(a,i,o,s,c,"next",e)}function c(e){r(a,i,o,s,c,"throw",e)}s(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:c,checkoutSessionId:s})}catch(e){return g(e.message),h.publish(o.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),v(this.cardForm,!0),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),v(this.clickToPay.element,!1),void h.publish(o.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 o.CLICK_TO_PAY_ERROR:"UNKNOWN"===t.data.data.error&&(this.consent=!1,e.checked=!1);break;case o.METHOD_CHANGE:var r=this._buyerExists&&"card"===t.data.data.method;this.consent=r,e.checked=r}}),"click-to-pay-consent-checkbox")}_initLearnMore(e){e.style.visibility="hidden",f.add("message",(t=>{t.data.type===o.CLICK_TO_PAY_INITIALIZED&&(e.style.visibility="visible",e.addEventListener("click",(()=>{this.controller.contentWindow.postMessage({type:"show-learn-more",channel:l},this.origin)})))}),"click-to-pay-learn-more")}init(e,t){return w((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,v(this.signIn,!1);var r=this.secureFields,n=r.apiUrl,i=r.config,a=i.gr4vyId,s=i.environment,c=i.sessionId,l=r.environmentPath;if(this.clickToPay={element:null,options:t,signIn:e=>{var t=e.email,r=e.mobileNumber;return w((function*(){var e=this.clickToPay,n=e.element,i=e.options;delete i.email,delete i.mobileNumber,n.innerHTML="",v(this.signIn,!1),h.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),v(this.cardForm,!1),h.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),this.secureFields.update("clickToPay",yield this.init(n,k({},i,t?{email:t}:{},r?{mobileNumber:r}:{})))})).call(this)},signOut:()=>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,p=k({gr4vyId:a,environment:s,sessionId:c},L({},function(e){if(null==e)throw new TypeError("Cannot destructure "+e);return e}(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(p))}),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(p))}),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.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){S(this,"secureFields",void 0),S(this,"_buyerExists",void 0),S(this,"consent",void 0),S(this,"controller",void 0),S(this,"encrypt",void 0),S(this,"origin",void 0),S(this,"url",void 0),S(this,"cardForm",void 0),S(this,"signIn",void 0),S(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}function D(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function j(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){D(e,t,r[t])}))}return e}function U(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 M{_postMessage(e){this.frame.contentWindow.postMessage(j({channel:l},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=j({},this.options,e);var t=P(j({},this.options.styles,e.styles)),r=U(j({},this.options,e),{styles:t});this._postMessage({type:"update",data:U(j({},r),{styles:t})}),g("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){if(D(this,"frameUrl",void 0),D(this,"parentOrigin",void 0),D(this,"frame",void 0),D(this,"type",void 0),D(this,"options",void 0),D(this,"addEventListener",void 0),D(this,"removeEventListener",void 0),e){var t=e.frameUrl,r=e.parentOrigin,n=e.font,i=e.options.type,o=e.paymentMethodScheme,a=function(e,t){if(null==e)return{};var r,n,i=function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(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.options,["type"]);this.frameUrl=t,this.parentOrigin=r,this.type=i,this.options=a;var s=P(a.styles);this.frame=document.createElement("iframe"),this.frame.id=i,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)),o&&(this.frame.src+="&paymentMethodScheme=".concat(o)),this.frame.onload=()=>{this._postMessage({type:"update",data:U(j({},this.options),{styles:s,type:i})}),g("Added field",this.options)}}}}function Y(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 R(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(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){R(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 x{static get Events(){return o}static get version(){return"#0ab3293099efc6789559fca0584ade6d10ed068d"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),h.publish(o.METHOD_CHANGE,r),g("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:l},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;m.some((e=>new RegExp(e).test(t)))&&i.setAttribute(t,r)})),(o=i).classList.add("secure-fields__input","secure-fields__input--".concat(C(t.type))),o.appendChild(t.frame),null===(r=e.parentNode)||void 0===r||r.replaceChild(o,e);var a=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":h.publish("".concat(t.type,":blur"),e.data.data),o.removeAttribute(s.FOCUSED),g("Field blurred",e.data.data);break;case"focus":h.publish("".concat(t.type,":focus"),e.data.data),o.setAttribute(s.FOCUSED,""),g("Field focused",e.data.data);break;case"input":h.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?o.removeAttribute(s.INVALID):o.setAttribute(s.INVALID,""),e.data.data.autofilled?o.setAttribute(s.AUTOFILLED,""):o.removeAttribute(s.AUTOFILLED),g("Field input changed",e.data.data)}};return f.remove("message",a,t.type),f.add("message",a,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.paymentMethodId&&O(c.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new M({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:K(F({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){var r,n;return this.securityCode||(this.securityCode=new M({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:K(F({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&&O(c.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new M({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:K(F({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addField(e,t){return this.otherFields[t.type]||(this.otherFields=K(F({},this.otherFields),{[t.type]:new M({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:t})})),this._addField(e,this.otherFields[t.type])}addClickToPay(e,t){return(r=function*(){if(!this.paymentMethodId)return this.clickToPayInstance=yield new N(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;O(c.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){Y(o,n,i,a,s,"next",e)}function s(e){Y(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===M?"".concat(r,":"):"").concat(e);h.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===M?"".concat(r,":"):"").concat(e);h.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),i=e.data.channel===l,a=["success","error"].includes(e.data.type);if(n&&i&&a){switch(e.data.type){case"success":var s;h.publish(o.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(O(e.data.data.warn),delete e.data.data.warn),g("Payment method tokenized successfully",e.data.data);break;case"error":h.publish(o.CARD_VAULT_FAILURE,e.data),g("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:l},this.clickToPayInstance.url):this.controller.contentWindow.postMessage({type:"submit",channel:l,data:{method:this.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(i,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){var t,r;R(this,"config",void 0),R(this,"controller",void 0),R(this,"frameUrl",void 0),R(this,"apiUrl",void 0),R(this,"parentOrigin",void 0),R(this,"font",void 0),R(this,"cardNumber",void 0),R(this,"securityCode",void 0),R(this,"expiryDate",void 0),R(this,"otherFields",{}),R(this,"method","card"),R(this,"clickToPayInstance",void 0),R(this,"clickToPay",void 0),R(this,"environmentPath",void 0),R(this,"paymentMethodId",void 0),h.unsubscribeAll(),this.config=F({environment:"production"},e),this.config.paymentMethodId&&!this.config.paymentMethod&&O(c.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 n=F({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{});null===(r=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===r||r.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=E("".concat(this.frameUrl,"/controller.html"),n),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 M,this.expiryDate=new M),g("Initialized",K(F({},this.config),{version:x.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var i=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=F({version:x.version},this.config);h.publish(o.READY,t),g("Ready",t);break;case"form-change":h.publish(o.FORM_CHANGE,e.data.data),g("Form change",e.data.data)}};f.remove("message",i,"init"),f.add("message",i,"init")}}return t})()));
package/lib/types.d.ts CHANGED
@@ -1,9 +1,17 @@
1
1
  import { Events } from './constants';
2
2
  import type * as CSS from 'csstype';
3
+ export type PaymentMethod = {
4
+ id: string;
5
+ scheme: string;
6
+ };
3
7
  export type Config = {
4
8
  environment?: 'sandbox' | 'production';
5
9
  gr4vyId: string;
10
+ /**
11
+ * @deprecated Use `paymentMethod` instead. This prop will be removed in a future version.
12
+ */
6
13
  paymentMethodId?: string;
14
+ paymentMethod?: PaymentMethod;
7
15
  sessionId: string;
8
16
  };
9
17
  export type InputConfig = {
@@ -11,8 +19,9 @@ export type InputConfig = {
11
19
  parentOrigin: string;
12
20
  font?: string;
13
21
  options: Field;
22
+ paymentMethodScheme?: string;
14
23
  };
15
- export type FieldType = 'number' | 'securityCode' | 'expiryDate';
24
+ export type FieldType = 'number' | 'securityCode' | 'expiryDate' | 'postalCode';
16
25
  export type Field = {
17
26
  type: FieldType;
18
27
  placeholder?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gr4vy/secure-fields",
3
- "version": "1.23.0",
3
+ "version": "2.0.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",
@@ -44,17 +44,17 @@
44
44
  "devDependencies": {
45
45
  "css-loader": "^6.11.0",
46
46
  "csstype": "^3.1.3",
47
- "dotenv": "^16.5.0",
47
+ "dotenv": "^16.6.1",
48
48
  "msw": "^1.3.5",
49
49
  "node-fetch": "^2.7.0",
50
50
  "style-loader": "^3.3.4",
51
51
  "ts-patch": "^2.1.0",
52
- "typedoc": "^0.28.5",
52
+ "typedoc": "^0.28.12",
53
53
  "typedoc-plugin-missing-exports": "^2.3.0",
54
54
  "typescript-transform-paths": "^3.5.5"
55
55
  },
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "8f78925935318c6e9d20d6146cf3a7369039ac62"
59
+ "gitHead": "0ab3293099efc6789559fca0584ade6d10ed068d"
60
60
  }