@gr4vy/secure-fields 2.6.0 → 2.7.1
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 +34 -0
- package/README.md +44 -27
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/types.d.ts +6 -1
- package/lib/utils/scheme-icons.d.ts +19 -5
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
# v2.7.1 (Wed May 20 2026)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- task: update scheme detection docs [#1222](https://github.com/gr4vy/secure-fields/pull/1222) ([@luca-gr4vy](https://github.com/luca-gr4vy) [@GiordanoArman](https://github.com/GiordanoArman))
|
|
6
|
+
|
|
7
|
+
#### 🏠 Internal
|
|
8
|
+
|
|
9
|
+
- chore(dev-deps): update dependency msw to ^2.14.6 [#1176](https://github.com/gr4vy/secure-fields/pull/1176) ([@renovate[bot]](https://github.com/renovate[bot]) [@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
10
|
+
|
|
11
|
+
#### Authors: 3
|
|
12
|
+
|
|
13
|
+
- [@renovate[bot]](https://github.com/renovate[bot])
|
|
14
|
+
- GiordanoArman ([@GiordanoArman](https://github.com/GiordanoArman))
|
|
15
|
+
- Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# v2.7.0 (Tue May 19 2026)
|
|
20
|
+
|
|
21
|
+
#### 🚀 Enhancement
|
|
22
|
+
|
|
23
|
+
- task: add additional card schemes icons [#1217](https://github.com/gr4vy/secure-fields/pull/1217) ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
24
|
+
|
|
25
|
+
#### 🐛 Bug Fix
|
|
26
|
+
|
|
27
|
+
- task: split CI jobs and run in parallel [#1216](https://github.com/gr4vy/secure-fields/pull/1216) ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
28
|
+
|
|
29
|
+
#### Authors: 1
|
|
30
|
+
|
|
31
|
+
- Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
1
35
|
# v2.6.0 (Wed May 13 2026)
|
|
2
36
|
|
|
3
37
|
#### 🚀 Enhancement
|
package/README.md
CHANGED
|
@@ -148,9 +148,9 @@ Mask the value of card number and security code fields to hide sensitive data.
|
|
|
148
148
|
```js
|
|
149
149
|
const number = secureFields.addCardNumberField('#cc-number', {
|
|
150
150
|
maskInput: {
|
|
151
|
-
character: '•',
|
|
152
|
-
showLastFour: true,
|
|
153
|
-
maskOnInput: true,
|
|
151
|
+
character: '•', // masking character (default: •)
|
|
152
|
+
showLastFour: true, // keep last 4 digits visible when valid (card number only)
|
|
153
|
+
maskOnInput: true, // mask in real-time as the user types (default: on blur only)
|
|
154
154
|
},
|
|
155
155
|
styles,
|
|
156
156
|
})
|
|
@@ -159,7 +159,7 @@ const number = secureFields.addCardNumberField('#cc-number', {
|
|
|
159
159
|
You can also mask and unmask a field programmatically:
|
|
160
160
|
|
|
161
161
|
```js
|
|
162
|
-
number.redactValue()
|
|
162
|
+
number.redactValue() // mask the value
|
|
163
163
|
number.unredactValue() // unmask the value
|
|
164
164
|
```
|
|
165
165
|
|
|
@@ -178,7 +178,9 @@ secureFields.setAutoAdvance({
|
|
|
178
178
|
|
|
179
179
|
### Scheme icons
|
|
180
180
|
|
|
181
|
-
Display
|
|
181
|
+
Display card scheme icons inside the card number field. Icons update in real-time as the user types and are refined when the API confirms the scheme.
|
|
182
|
+
|
|
183
|
+
Pass `true` to show the detected scheme icon along with any additional schemes (e.g. co-branded cards):
|
|
182
184
|
|
|
183
185
|
```js
|
|
184
186
|
const number = secureFields.addCardNumberField('#cc-number', {
|
|
@@ -187,6 +189,21 @@ const number = secureFields.addCardNumberField('#cc-number', {
|
|
|
187
189
|
})
|
|
188
190
|
```
|
|
189
191
|
|
|
192
|
+
For granular control, pass an object to choose which icons to display:
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
const number = secureFields.addCardNumberField('#cc-number', {
|
|
196
|
+
showSchemeIcons: {
|
|
197
|
+
scheme: true, // show the detected card scheme icon (default: false)
|
|
198
|
+
additionalSchemes: true, // show additional scheme icons, e.g. co-branded (default: false)
|
|
199
|
+
placeholders: true, // show placeholder icons (Visa, Mastercard, Amex) before detection (default: false)
|
|
200
|
+
},
|
|
201
|
+
styles,
|
|
202
|
+
})
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
> **Note**: A maximum of 3 icons are visible at any time. In co-branded scenarios, the primary scheme icon is displayed first, followed by additional schemes. Ensure the card number input is wide enough to accommodate up to 3 icons.
|
|
206
|
+
|
|
190
207
|
For more information please
|
|
191
208
|
refer to the [Secure Fields get started guide](https://docs.gr4vy.com/guides/payments/secure-fields/quick-start/overview).
|
|
192
209
|
|
|
@@ -303,14 +320,14 @@ The following events can be listened to by attaching an event handler to a field
|
|
|
303
320
|
|
|
304
321
|
Some of these provide additional useful data like the card BIN, validation status, and scheme. For example, the input event on a card number field might include `{ schema: 'visa', codeLabel: 'CVV', valid: true, ... }`.
|
|
305
322
|
|
|
306
|
-
| Name
|
|
307
|
-
|
|
|
308
|
-
| `blur`
|
|
309
|
-
| `focus`
|
|
310
|
-
| `input`
|
|
311
|
-
| `redacted`
|
|
312
|
-
| `unredacted`
|
|
313
|
-
| `card-details-changed` | Triggered when the API confirms card details for the entered BIN. Includes the confirmed `scheme` and other card metadata. Only fires on the card number field. | `cardNumberField.addEventListener('card-details-changed', (data) => { console.log(data) /* { id: 'number', scheme: 'visa', ... } */ })`
|
|
323
|
+
| Name | Description | Example |
|
|
324
|
+
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
325
|
+
| `blur` | Triggered when the field loses focus. | `cardNumberField.addEventListener('blur', (data) => { console.log(data) /* { id: 'number' } */ })` |
|
|
326
|
+
| `focus` | Triggered when the field gains focus. | `cardNumberField.addEventListener('focus', (data) => { console.log(data) /* { id: 'number' } */ })` |
|
|
327
|
+
| `input` | Triggered when the field value has been changed. | `cardNumberField.addEventListener('input', (data) => { console.log(data) /* { id: 'number', schema: 'visa', codeLabel: 'CVV', valid: true, empty: true, autofilled: false, bin: '411111' } */` |
|
|
328
|
+
| `redacted` | Triggered when the field value has been masked (either automatically via `maskInput` or programmatically via `redactValue()`). | `cardNumberField.addEventListener('redacted', () => { console.log('Field redacted') })` |
|
|
329
|
+
| `unredacted` | Triggered when the field value has been unmasked (either automatically or programmatically via `unredactValue()`). | `cardNumberField.addEventListener('unredacted', () => { console.log('Field unredacted') })` |
|
|
330
|
+
| `card-details-changed` | Triggered when the API confirms card details for the entered BIN. Includes the confirmed `scheme`, `additionalSchemes` (co-branded networks), and other card metadata. Only fires on the card number field. | `cardNumberField.addEventListener('card-details-changed', (data) => { console.log(data) /* { id: 'number', scheme: 'visa', additionalSchemes: ['mastercard'], ... } */ })` |
|
|
314
331
|
|
|
315
332
|
## Click to Pay
|
|
316
333
|
|
|
@@ -441,25 +458,25 @@ The following Click to Pay events can be listened to by attaching an event handl
|
|
|
441
458
|
| `submit` | Calls the Vault API to tokenize and store the card data. <br /><br />`secureFields.submit()` |
|
|
442
459
|
| `setDebug` | Enable / disable debug mode. When the debug mode is enabled, SecureFields logs information to the console. <br /><br />`secureFields.setDebug(true)` |
|
|
443
460
|
| `addFont` | Load a custom font from [Google Fonts](https://fonts.google.com/) to be used inside inputs. You can define the font family as well as styles or weights as a string (e.g. "Lato:400,600"). To use the loaded font, add the correct `fontFamily` property to the styles object when creating fields. <br /><br />`secureFields.addFont('Lato')` |
|
|
444
|
-
| `setAutoAdvance` | Enable auto-advance to automatically move focus to the next field when the current field's value is complete and valid. Accepts `{ enabled: boolean, fieldOrder?: Array<FieldType> }`. <br /><br />`secureFields.setAutoAdvance({ enabled: true })`
|
|
461
|
+
| `setAutoAdvance` | Enable auto-advance to automatically move focus to the next field when the current field's value is complete and valid. Accepts `{ enabled: boolean, fieldOrder?: Array<FieldType> }`. <br /><br />`secureFields.setAutoAdvance({ enabled: true })` |
|
|
445
462
|
|
|
446
463
|
### Field methods
|
|
447
464
|
|
|
448
|
-
| Name
|
|
449
|
-
|
|
|
450
|
-
| `clear`
|
|
451
|
-
| `redactValue`
|
|
452
|
-
| `unredactValue`
|
|
465
|
+
| Name | Description |
|
|
466
|
+
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
467
|
+
| `clear` | Resets the value of a field. <br /><br />`cardNumberField.clear()` |
|
|
468
|
+
| `redactValue` | Masks the field value programmatically. To apply masking behavior, configure `maskInput` for the field. <br /><br />`cardNumberField.redactValue()` |
|
|
469
|
+
| `unredactValue` | Unmasks the field value programmatically. To apply masking behavior, configure `maskInput` for the field. <br /><br />`cardNumberField.unredactValue()` |
|
|
453
470
|
|
|
454
471
|
### Field options
|
|
455
472
|
|
|
456
473
|
The following options can be passed when adding a field (e.g. `addCardNumberField('#el', options)`).
|
|
457
474
|
|
|
458
|
-
| Name
|
|
459
|
-
|
|
|
460
|
-
| `placeholder`
|
|
461
|
-
| `styles`
|
|
462
|
-
| `label`
|
|
463
|
-
| `autoFocus`
|
|
464
|
-
| `maskInput`
|
|
465
|
-
| `showSchemeIcons` | `boolean` | Display
|
|
475
|
+
| Name | Type | Description |
|
|
476
|
+
| ----------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
477
|
+
| `placeholder` | `string` | Input placeholder text. |
|
|
478
|
+
| `styles` | `object` | CSS styles for the input inside the iframe. |
|
|
479
|
+
| `label` | `string` | Accessible label for the input. |
|
|
480
|
+
| `autoFocus` | `boolean` | Automatically focus the field when loaded. |
|
|
481
|
+
| `maskInput` | `boolean \| object` | Enable input masking. Use `true` for default masking, or pass an options object: `character` (masking character), `showLastFour` (card number only), `maskOnInput` (real-time mask). |
|
|
482
|
+
| `showSchemeIcons` | `boolean \| object` | Display card scheme icons inside the card number field. Icons update in real-time as the user types and are refined when the API confirms the scheme. Accepts `true` to show scheme and additional scheme icons, or an object for granular control which accepts:<br><br>• `scheme`: (boolean) show detected scheme<br>• `additionalSchemes`: (boolean) show co-branded icons<br>• `placeholders`: (boolean) show Visa/Mastercard/Amex before detection<br><br>A maximum of 3 icons are shown — ensure the input is wide enough to accommodate them. Only available on `addCardNumberField`. |
|
package/lib/index.d.ts
CHANGED
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:()=>o,SecureFields:()=>X,SecureInput:()=>q});var r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production";return"https://".concat(arguments.length>2?arguments[2]:void 0,".").concat("sandbox"===t?"sandbox.":"").concat(e,".gr4vy.app")},n=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()),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.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}({}),a=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}({}),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.FIELD_PATTERN_IN_USE="The `pattern` option can't be used on card fields, so it won't be applied here.",e.AUTO_ADVANCE_ENABLED="autoAdvance is enabled. Auto-advancing focus on field completion can degrade checkout UX (see WCAG 3.2.2). Use with caution.",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}({}),l="secure-fields",d={number:"addCardNumberField",expiryDate:"addExpiryDateField",securityCode:"addSecurityCodeField"},u=["01","02","03","04","05"];function h(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 p(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 h(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)?h(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 y=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=p(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=p(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 m(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 f(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 m(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)?m(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 v=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=f(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=f(this.listeners.splice(n,1),1),o=f(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=f(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=["number","expiryDate","securityCode","postalCode"],_=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]},g=["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"],I=(e,t)=>e&&(e.style.display=t?"block":"none");function O(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function C(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){O(e,t,r[t])}))}return e}var E={debug:!1,level:"log"},T=(e,t,r)=>{var n=C({},E,r),o=n.debug,a=n.level;(o||"true"===localStorage.getItem(i))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},A=(e,t,r)=>{var n,i;T(e,t,(n=C({},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))},P=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function w(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 S=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 w(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)?w(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=P(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function N(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 k(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(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){k(e,t,r[t])}))}return e}function D(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 R{init(e,t){var r;this.challengeWindowSize=u.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===(r=document.body.querySelector("iframe#".concat(i)))||void 0===r||r.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=n(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:l,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}),v.remove("message",this.listener.bind(this),"three-ds"),v.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 o.THREE_DS_START:y.publish(o.THREE_DS_START,D(L({},n),{element:this.element})),T("3DS start",e.data.data);break;case o.THREE_DS_FINISH:y.publish(o.THREE_DS_FINISH,D(L({},n),{element:this.element})),T("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){N(o,n,i,a,s,"next",e)}function s(e){N(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}constructor(e){k(this,"secureFields",void 0),k(this,"controller",void 0),k(this,"challengeWindowSize",void 0),k(this,"element",void 0),this.secureFields=e}}function U(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 j extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function F(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 M(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){F(o,n,i,a,s,"next",e)}function s(e){F(o,n,i,a,s,"throw",e)}a(void 0)}))}}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 Y(){return Y=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},Y.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){x(e,t,r[t])}))}return e}class H{_addIframe(e,t,r,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=n(r,i),o}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,i=r.data,s=i.type,d=i.data;switch(n){case this.origin:switch(s){case o.RESIZE:this.controller.style.height="".concat(d.height>0?d.height+48:0,"px");break;case o.METHOD_CHANGE:var u=d.method||"card";(this.secureFields.method!==u||t)&&(t=!1,this.secureFields.updateMethod(u,{data:d}),I(this.cardForm,"card"===u),y.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===u));break;case o.CLICK_TO_PAY_INITIALIZED:y.publish(o.CLICK_TO_PAY_INITIALIZED,this.clickToPay),T("Click to Pay initialized",this.clickToPay),I(this.signIn,!1),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),I(this.clickToPay.element,!0),y.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_READY:this._buyerExists=d.buyerExists,y.publish(o.CLICK_TO_PAY_READY,d),T("Click to Pay ready"),I(this.signIn,!d.buyerExists),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!d.buyerExists),I(this.clickToPay.element,!0),y.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_SIGN_OUT:this.clickToPay.signOut();break;case o.CLICK_TO_PAY_ERROR:y.publish(o.CLICK_TO_PAY_ERROR,d),T("Click to Pay error:",d),I(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),I(this.clickToPay.element,"UNKNOWN"!==d.error),y.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==d.error);break;case o.CLICK_TO_PAY_CANCEL:y.publish(o.CLICK_TO_PAY_CANCEL,d),T("Click to Pay cancelled"),this._buyerExists||(I(this.signIn,!0),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:y.publish(o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,d),I(this.signIn,!1),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),T("Click to Pay checkout with new card initiated");break;case o.CLICK_TO_PAY_PROCESSING:I(this.cardForm,!d),y.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,d),T("Click to Pay processing",d);break;case o.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 o.CLICK_TO_PAY_AUTHENTICATE_FAILURE:y.publish(o.CLICK_TO_PAY_AUTHENTICATE_FAILURE,d),T("Click to Pay authenticate failure:",d);break;case a.REQUEST_RECOGNITION_TOKEN:this.controller.contentWindow.postMessage({channel:l,type:a.RECOGNITION_TOKEN,data:{recognitionToken:_("recognitionToken")}},this.origin);break;case a.REQUEST_RECOGNITION_TOKEN_FAILED:A(c.NO_RECOGNITION_TOKEN);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])}};v.remove("message",r,"click-to-pay"),v.add("message",r,"click-to-pay")}_fetchDPA(e,t){return M((function*(e,t){var n=t.gr4vyId,i=t.environment,a=t.sessionId;try{var s=e||function(e){return r(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production","api")}(n,i);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 j("Unable to load DPA")}catch(e){throw new j("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){U(o,n,i,a,s,"next",e)}function s(e){U(o,n,i,a,s,"throw",e)}a(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:s,checkoutSessionId:a})}catch(e){return T(e.message),y.publish(o.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),I(this.cardForm,!0),y.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),I(this.clickToPay.element,!1),void y.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})),v.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")}_setNewCardRememberMe(e){this.controller.contentWindow.postMessage({type:"remember-me-new-card-changed",channel:l,data:{value:e}},this.origin)}_initNewCardRememberMeCheckbox(e){e.addEventListener("change",(e=>{var t=e.target;this._setNewCardRememberMe(t.checked)})),v.add("message",(t=>{switch(t.data.type){case o.CLICK_TO_PAY_INITIALIZED:this._setNewCardRememberMe(e.checked);break;case o.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",v.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 M((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,I(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 M((function*(){var e=this.clickToPay,n=e.element,i=e.options;delete i.email,delete i.mobileNumber,n.innerHTML="",I(this.signIn,!1),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),I(this.cardForm,!1),y.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._buyerExists=!1,y.publish(o.CLICK_TO_PAY_SIGN_OUT),T("Click to pay signed out"),I(this.signIn,!0),y.publish(o.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),K({gr4vyId:a,environment:s,sessionId:c},Y({},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 p="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;p&&this._initConsentCheckbox(p)}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){x(this,"secureFields",void 0),x(this,"_buyerExists",void 0),x(this,"consent",void 0),x(this,"controller",void 0),x(this,"encrypt",void 0),x(this,"origin",void 0),x(this,"url",void 0),x(this,"cardForm",void 0),x(this,"signIn",void 0),x(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}function G(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 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 W(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}function B(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 q{_postMessage(e){return(t=function*(){yield this.ready,this.frame.contentWindow.postMessage(W({channel:l},e),this.frameUrl)},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function a(e){G(o,n,i,a,s,"next",e)}function s(e){G(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}update(e){if(this.frameUrl){this.options=W({},this.options,e);var t=S(W({},this.options.styles,e.styles)),r=B(W({},this.options,e),{styles:t});this._postMessage({type:"update",data:B(W({},r),{styles:t})}),T("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}}),T("Cleared field",{type:e})}}focus(){if(this.frameUrl){var e=this.type;this._postMessage({type:"focus",data:{type:e}}),T("Focus field",{type:e})}}redactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"redact-value",data:{type:e}}),T("Redact field",{type:e})}}unredactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"unredact-value",data:{type:e}}),T("Unredact field",{type:e})}}setEnterKeyHint(e){if(this.frameUrl){var t=this.type;this._postMessage({type:"set-enter-key-hint",data:{type:t,value:e}}),T("Updated enter key hint",{type:t,value:e})}}constructor(e){if(V(this,"frameUrl",void 0),V(this,"parentOrigin",void 0),V(this,"frame",void 0),V(this,"type",void 0),V(this,"options",void 0),V(this,"addEventListener",void 0),V(this,"removeEventListener",void 0),V(this,"ready",void 0),V(this,"_resolveReady",void 0),V(this,"complete",void 0),e){this.ready=new Promise((e=>{this._resolveReady=e}));var t=e.frameUrl,r=e.parentOrigin,i=e.font,o=e.sessionId,a=e.gr4vyId,s=e.environment,c=e.options,l=c.type,d=c.autoFocus,u=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}(c,["type","autoFocus"]),h=e.paymentMethodScheme;this.frameUrl=t,this.parentOrigin=r,this.type=l,this.options=u;var p=S(u.styles),y={parentOrigin:r,type:l,sessionId:o,gr4vyId:a,environment:s};this.frame=document.createElement("iframe"),this.frame.id=l,this.frame.src=n("".concat(t,"/input.html"),y),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%",i&&(this.frame.src+="&font=".concat(i)),h&&(this.frame.src+="&paymentMethodScheme=".concat(h)),this.frame.onload=()=>{this._postMessage({type:"update",data:B(W({},this.options),{styles:p,type:l})}),T("Added field",this.options),d&&this.focus()}}}}function z(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 Z(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){Z(e,t,r[t])}))}return e}function J(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}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}class X{static get Events(){return o}static get version(){return"#680b6d541e78acf43fc5b6703d7aad37e9881684"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),y.publish(o.METHOD_CHANGE,r),T("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:l},this.frameUrl)}setAutoAdvance(e){e.enabled&&(A(c.AUTO_ADVANCE_ENABLED),this.autoAdvance=(e=>{var t=e.enabled,r=e.secureFields,n=(e=>{if(!(null==e?void 0:e.length))return b;var t=e.filter(((t,r)=>b.includes(t)&&e.indexOf(t)===r)),r=b.filter((e=>!t.includes(e)));return[...t,...r]})(e.fieldOrder),i=e=>e?"number"===e?r.cardNumber:"expiryDate"===e?r.expiryDate:"securityCode"===e?r.securityCode:r.otherFields[e]:null,o=e=>{var t=e.type,r=e.nextIndex,a=null!=r?r:n.indexOf(t);if(!(a<0||a>=n.length-1)){var s=i(n[a+1]);!(null==s?void 0:s.complete)&&(null==s?void 0:s.frame)?s.focus():o({nextIndex:a+1})}};return{get enabled(){return t},get fieldOrder(){return n},updateEnterKeyHint:e=>{var r;if(null==e?void 0:e.frame){var o=n.indexOf(e.type),a=n[o+1],s=a&&(null===(r=i(a))||void 0===r?void 0:r.frame);e.setEnterKeyHint(t&&s?"next":"done")}},trigger:o}})(J(Q({},e),{secureFields:this})))}_addField(e,t,r){if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var n=e.closest("[data-secure-fields-input-group]"),i=null!=n?n:document.createElement("div"),o=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":y.publish("".concat(t.type,":blur"),e.data.data),i.removeAttribute(s.FOCUSED),T("Field blurred",e.data.data);break;case"focus":y.publish("".concat(t.type,":focus"),e.data.data),i.setAttribute(s.FOCUSED,""),T("Field focused",e.data.data);break;case"input":var n,o,a=e.data.data,c=a.complete,l=a.fromBlur,d=a.isDeleteInputType,u=$(a,["complete","fromBlur","isDeleteInputType"]);y.publish("".concat(t.type,":input"),u),t.complete=c,e.data.data.valid?i.removeAttribute(s.INVALID):i.setAttribute(s.INVALID,""),e.data.data.autofilled?i.setAttribute(s.AUTOFILLED,""):i.removeAttribute(s.AUTOFILLED),(null===(n=this.autoAdvance)||void 0===n?void 0:n.enabled)&&c&&!u.autofilled&&!1===l&&!d&&this.autoAdvance.trigger({type:t.type}),this.schemeIcons&&"number"===t.type&&(u.bin||(this.cardDetailsScheme=null),this.schemeIcons.toggleScheme(null!==(o=this.cardDetailsScheme)&&void 0!==o?o:u.schema)),T("Field input changed",u);break;case"redacted":y.publish("".concat(t.type,":redacted"),e.data.data),T("Field redacted",e.data.data);break;case"unredacted":y.publish("".concat(t.type,":unredacted"),e.data.data),T("Field unredacted",e.data.data);break;case"card-details-changed":this.cardDetailsScheme=e.data.data.scheme,y.publish("".concat(t.type,":card-details-changed"),e.data.data),this.schemeIcons&&this.schemeIcons.showScheme(e.data.data.scheme),T("Card details changed",e.data.data)}};return v.remove("message",o,t.type),v.add("message",o,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,this.controllerReady.then((()=>{var o,a,s,c;o=e,a=i,Array.from(o.attributes).forEach((e=>{var t=e.name,r=e.value;g.some((e=>new RegExp(e).test(t)))&&a.setAttribute(t,r)})),(i=a).classList.add("secure-fields__input","secure-fields__input--".concat(P(t.type))),n?(null===(s=e.parentNode)||void 0===s||s.replaceChild(t.frame,e),n.style.display="inline-flex",n.style.alignItems="center",t.frame.style.minWidth="0"):(null===(c=e.parentNode)||void 0===c||c.replaceChild(i,e),i.appendChild(t.frame)),"number"===t.type&&(null==r?void 0:r.showSchemeIcons)&&(i.style.display="inline-flex",i.style.alignItems="center",this.schemeIcons=(()=>{var e={baseUrl:"".concat(this.cdnBaseUrl,"/assets/icons/card-schemes")}.baseUrl,t=!1,r=document.createElement("div");r.classList.add("scheme-icons"),r.style.display="flex",r.style.marginRight="4px";var n=document.createElement("img");n.setAttribute("alt",""),n.setAttribute("aria-hidden","true"),n.style.display="none",n.onerror=()=>{t=!0,n.style.display="none"},r.appendChild(n);var i=r=>{if(r){var i="".concat(e,"/").concat(r,".svg");n.getAttribute("src")!==i?(t=!1,n.style.display="block",n.setAttribute("src",i),n.width=48):t||(n.style.display="block")}},o=()=>{n.style.display="none"};return{container:r,scheme:n,showScheme:i,hideScheme:o,toggleScheme:e=>{e?i(e):o()}}})(),t.frame.after(this.schemeIcons.container)),t._resolveReady(),t.frame.addEventListener("load",(()=>{var e;return null===(e=this.autoAdvance)||void 0===e?void 0:e.updateEnterKeyHint(t)}))})),t}addCardNumberField(e,t){return this.paymentMethodId&&A(c.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new q(J(Q({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{}),{options:J(Q({label:"Card number"},t),{type:"number"})}))),this._addField(e,this.cardNumber,t)}addSecurityCodeField(e,t){var r,n;return this.securityCode||(this.securityCode=new q({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:J(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&&A(c.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new q({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:J(Q({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addField(e,t){if(["number","expiryDate","securityCode"].includes(t.type)){t.pattern&&A(c.FIELD_PATTERN_IN_USE,Q({method:"addField"},t)),t.pattern,t.type;var r=$(t,["pattern","type"]);return this[d[t.type]](e,r)}return this.otherFields[t.type]||(this.otherFields=J(Q({},this.otherFields),{[t.type]:new q({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 R(this),this.threeDS.init(e,t))}addClickToPay(e,t){return(r=function*(){if(!this.paymentMethodId)return this.clickToPayInstance=yield new H(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;A(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){z(o,n,i,a,s,"next",e)}function s(e){z(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===q?"".concat(r,":"):"").concat(e);y.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===q?"".concat(r,":"):"").concat(e);y.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;y.publish(o.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(A(e.data.data.warn),delete e.data.data.warn),T("Payment method tokenized successfully",e.data.data);break;case"error":y.publish(o.CARD_VAULT_FAILURE,e.data),T("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,i;Z(this,"config",void 0),Z(this,"controller",void 0),Z(this,"frameUrl",void 0),Z(this,"apiUrl",void 0),Z(this,"cdnBaseUrl",void 0),Z(this,"parentOrigin",void 0),Z(this,"font",void 0),Z(this,"cardNumber",void 0),Z(this,"securityCode",void 0),Z(this,"expiryDate",void 0),Z(this,"otherFields",{}),Z(this,"method","card"),Z(this,"clickToPayInstance",void 0),Z(this,"clickToPay",void 0),Z(this,"threeDS",void 0),Z(this,"environmentPath",void 0),Z(this,"paymentMethodId",void 0),Z(this,"autoAdvance",null),Z(this,"schemeIcons",null),Z(this,"cardDetailsScheme",null),Z(this,"controllerReady",void 0),Z(this,"_resolveControllerReady",void 0),y.unsubscribeAll(),this.config=Q({environment:"production"},e),this.controllerReady=new Promise((e=>{var t=Date.now();this._resolveControllerReady=()=>e(Date.now()-t)})),this.config.paymentMethodId&&!this.config.paymentMethod&&A(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,this.cdnBaseUrl=function(e){return r(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production","cdn")}(this.config.gr4vyId,this.config.environment);var a=Q({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{});null===(i=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===i||i.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=n("".concat(this.frameUrl,"/controller.html"),a),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 q,this.expiryDate=new q),T("Initialized",J(Q({},this.config),{version:X.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var s=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=Q({version:X.version},this.config);y.publish(o.READY,t),this._resolveControllerReady(),T("Ready",t);break;case"form-change":y.publish(o.FORM_CHANGE,e.data.data),T("Form change",e.data.data)}};v.remove("message",s,"init"),v.add("message",s,"init"),this.controllerReady.then((e=>T("Loaded controller after ".concat(e," milliseconds"))))}}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:()=>o,SecureFields:()=>te,SecureInput:()=>Z});var r=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production";return"https://".concat(arguments.length>2?arguments[2]:void 0,".").concat("sandbox"===t?"sandbox.":"").concat(e,".gr4vy.app")},n=(e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()),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.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}({}),a=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}({}),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.FIELD_PATTERN_IN_USE="The `pattern` option can't be used on card fields, so it won't be applied here.",e.AUTO_ADVANCE_ENABLED="autoAdvance is enabled. Auto-advancing focus on field completion can degrade checkout UX (see WCAG 3.2.2). Use with caution.",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}({}),l="secure-fields",d={number:"addCardNumberField",expiryDate:"addExpiryDateField",securityCode:"addSecurityCodeField"},h=["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 p(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 y=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=p(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=p(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 m(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 f(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 m(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)?m(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 v=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=f(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=f(this.listeners.splice(n,1),1),o=f(i[0],2),a=o[0],s=o[1];window.removeEventListener(a,s)}}removeAll(){this.listeners.forEach((e=>{var t=f(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=["number","expiryDate","securityCode","postalCode"],g=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]},_=["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"],I=(e,t)=>e&&(e.style.display=t?"block":"none");function O(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function C(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){O(e,t,r[t])}))}return e}var E={debug:!1,level:"log"},T=(e,t,r)=>{var n=C({},E,r),o=n.debug,a=n.level;(o||"true"===localStorage.getItem(i))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},A=(e,t,r)=>{var n,i;T(e,t,(n=C({},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))};function P(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var S=["visa","mastercard","amex"],w=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function N(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 k=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 N(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)?N(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=w(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function L(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 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 R(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 j{init(e,t){var r;this.challengeWindowSize=h.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===(r=document.body.querySelector("iframe#".concat(i)))||void 0===r||r.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=n(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:l,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}),v.remove("message",this.listener.bind(this),"three-ds"),v.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 o.THREE_DS_START:y.publish(o.THREE_DS_START,U(R({},n),{element:this.element})),T("3DS start",e.data.data);break;case o.THREE_DS_FINISH:y.publish(o.THREE_DS_FINISH,U(R({},n),{element:this.element})),T("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){L(o,n,i,a,s,"next",e)}function s(e){L(o,n,i,a,s,"throw",e)}a(void 0)}))}).call(this);var t}constructor(e){D(this,"secureFields",void 0),D(this,"controller",void 0),D(this,"challengeWindowSize",void 0),D(this,"element",void 0),this.secureFields=e}}function F(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 M extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function x(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 Y(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){x(o,n,i,a,s,"next",e)}function s(e){x(o,n,i,a,s,"throw",e)}a(void 0)}))}}function K(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(){return H=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},H.apply(this,arguments)}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){K(e,t,r[t])}))}return e}class V{_addIframe(e,t,r,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=n(r,i),o}_attachListeners(){var e=new MessageChannel,t=!0,r=r=>{var n=r.origin,i=r.data,s=i.type,d=i.data;switch(n){case this.origin:switch(s){case o.RESIZE:this.controller.style.height="".concat(d.height>0?d.height+48:0,"px");break;case o.METHOD_CHANGE:var h=d.method||"card";(this.secureFields.method!==h||t)&&(t=!1,this.secureFields.updateMethod(h,{data:d}),I(this.cardForm,"card"===h),y.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,"card"===h));break;case o.CLICK_TO_PAY_INITIALIZED:y.publish(o.CLICK_TO_PAY_INITIALIZED,this.clickToPay),T("Click to Pay initialized",this.clickToPay),I(this.signIn,!1),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),I(this.clickToPay.element,!0),y.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_READY:this._buyerExists=d.buyerExists,y.publish(o.CLICK_TO_PAY_READY,d),T("Click to Pay ready"),I(this.signIn,!d.buyerExists),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!d.buyerExists),I(this.clickToPay.element,!0),y.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,!0);break;case o.CLICK_TO_PAY_SIGN_OUT:this.clickToPay.signOut();break;case o.CLICK_TO_PAY_ERROR:y.publish(o.CLICK_TO_PAY_ERROR,d),T("Click to Pay error:",d),I(this.signIn,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!["UNKNOWN","INVALID_CARD","CODE_INVALID"].includes(d.error)),I(this.clickToPay.element,"UNKNOWN"!==d.error),y.publish(o.CLICK_TO_PAY_VISIBILITY_CHANGE,"UNKNOWN"!==d.error);break;case o.CLICK_TO_PAY_CANCEL:y.publish(o.CLICK_TO_PAY_CANCEL,d),T("Click to Pay cancelled"),this._buyerExists||(I(this.signIn,!0),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!0));break;case o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:y.publish(o.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,d),I(this.signIn,!1),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),T("Click to Pay checkout with new card initiated");break;case o.CLICK_TO_PAY_PROCESSING:I(this.cardForm,!d),y.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,d),T("Click to Pay processing",d);break;case o.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 o.CLICK_TO_PAY_AUTHENTICATE_FAILURE:y.publish(o.CLICK_TO_PAY_AUTHENTICATE_FAILURE,d),T("Click to Pay authenticate failure:",d);break;case a.REQUEST_RECOGNITION_TOKEN:this.controller.contentWindow.postMessage({channel:l,type:a.RECOGNITION_TOKEN,data:{recognitionToken:g("recognitionToken")}},this.origin);break;case a.REQUEST_RECOGNITION_TOKEN_FAILED:A(c.NO_RECOGNITION_TOKEN);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])}};v.remove("message",r,"click-to-pay"),v.add("message",r,"click-to-pay")}_fetchDPA(e,t){return Y((function*(e,t){var n=t.gr4vyId,i=t.environment,a=t.sessionId;try{var s=e||function(e){return r(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production","api")}(n,i);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 M("Unable to load DPA")}catch(e){throw new M("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){F(o,n,i,a,s,"next",e)}function s(e){F(o,n,i,a,s,"throw",e)}a(void 0)}))}).apply(this,arguments);var t}({apiBaseUrl:s,checkoutSessionId:a})}catch(e){return T(e.message),y.publish(o.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA),I(this.cardForm,!0),y.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!0),I(this.clickToPay.element,!1),void y.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})),v.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")}_setNewCardRememberMe(e){this.controller.contentWindow.postMessage({type:"remember-me-new-card-changed",channel:l,data:{value:e}},this.origin)}_initNewCardRememberMeCheckbox(e){e.addEventListener("change",(e=>{var t=e.target;this._setNewCardRememberMe(t.checked)})),v.add("message",(t=>{switch(t.data.type){case o.CLICK_TO_PAY_INITIALIZED:this._setNewCardRememberMe(e.checked);break;case o.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",v.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 Y((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,I(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 Y((function*(){var e=this.clickToPay,n=e.element,i=e.options;delete i.email,delete i.mobileNumber,n.innerHTML="",I(this.signIn,!1),y.publish(o.CLICK_TO_PAY_SIGN_IN_VISIBILITY_CHANGE,!1),I(this.cardForm,!1),y.publish(o.CLICK_TO_PAY_CARD_FORM_VISIBILITY_CHANGE,!1),this.secureFields.update("clickToPay",yield this.init(n,G({},i,t?{email:t}:{},r?{mobileNumber:r}:{})))})).call(this)},signOut:()=>(this._buyerExists=!1,y.publish(o.CLICK_TO_PAY_SIGN_OUT),T("Click to pay signed out"),I(this.signIn,!0),y.publish(o.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 h=window.location.origin,u=(function(e){if(null==e)throw new TypeError("Cannot destructure "+e)}(t),G({gr4vyId:a,environment:s,sessionId:c},H({},t)));if(this.controller=this._addIframe("click-to-pay-controller","Click To Pay","".concat(this.url,"/click-to-pay.html"),{parentOrigin:h,environment:s,config:encodeURIComponent(JSON.stringify(u))}),this.encrypt=this._addIframe("click-to-pay-encrypt","Click To Pay Encrypt","".concat(this.secureFields.frameUrl,"/click-to-pay-encrypt.html"),{parentOrigin:h,environment:s,config:encodeURIComponent(JSON.stringify(u))}),this._attachListeners(),null==t?void 0:t.consentCheckbox){var p="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;p&&this._initConsentCheckbox(p)}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){K(this,"secureFields",void 0),K(this,"_buyerExists",void 0),K(this,"consent",void 0),K(this,"controller",void 0),K(this,"encrypt",void 0),K(this,"origin",void 0),K(this,"url",void 0),K(this,"cardForm",void 0),K(this,"signIn",void 0),K(this,"clickToPay",void 0),this.secureFields=e,this._buyerExists=!1,this.consent=!1}}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{_postMessage(e){return(t=function*(){yield this.ready,this.frame.contentWindow.postMessage(q({channel:l},e),this.frameUrl)},function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);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 t}update(e){if(this.frameUrl){this.options=q({},this.options,e);var t=k(q({},this.options.styles,e.styles)),r=z(q({},this.options,e),{styles:t});this._postMessage({type:"update",data:z(q({},r),{styles:t})}),T("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}}),T("Cleared field",{type:e})}}focus(){if(this.frameUrl){var e=this.type;this._postMessage({type:"focus",data:{type:e}}),T("Focus field",{type:e})}}redactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"redact-value",data:{type:e}}),T("Redact field",{type:e})}}unredactValue(){if(this.frameUrl){var e=this.type;this._postMessage({type:"unredact-value",data:{type:e}}),T("Unredact field",{type:e})}}setEnterKeyHint(e){if(this.frameUrl){var t=this.type;this._postMessage({type:"set-enter-key-hint",data:{type:t,value:e}}),T("Updated enter key hint",{type:t,value:e})}}constructor(e){if(B(this,"frameUrl",void 0),B(this,"parentOrigin",void 0),B(this,"frame",void 0),B(this,"type",void 0),B(this,"options",void 0),B(this,"addEventListener",void 0),B(this,"removeEventListener",void 0),B(this,"ready",void 0),B(this,"_resolveReady",void 0),B(this,"complete",void 0),e){this.ready=new Promise((e=>{this._resolveReady=e}));var t=e.frameUrl,r=e.parentOrigin,i=e.font,o=e.sessionId,a=e.gr4vyId,s=e.environment,c=e.options,l=c.type,d=c.autoFocus,h=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}(c,["type","autoFocus"]),u=e.paymentMethodScheme;this.frameUrl=t,this.parentOrigin=r,this.type=l,this.options=h;var p=k(h.styles),y={parentOrigin:r,type:l,sessionId:o,gr4vyId:a,environment:s};this.frame=document.createElement("iframe"),this.frame.id=l,this.frame.src=n("".concat(t,"/input.html"),y),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%",i&&(this.frame.src+="&font=".concat(i)),u&&(this.frame.src+="&paymentMethodScheme=".concat(u)),this.frame.onload=()=>{this._postMessage({type:"update",data:z(q({},this.options),{styles:p,type:l})}),T("Added field",this.options),d&&this.focus()}}}}function Q(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 J(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){J(e,t,r[t])}))}return e}function X(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}function ee(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}class te{static get Events(){return o}static get version(){return"#83a98fd6f3322aaa7229e49ae89671b4453cfde4"}update(e,t){this[e]=t}updateMethod(e,t){var r=t.data;this.update("method",e),y.publish(o.METHOD_CHANGE,r),T("Method changed",{method:e}),this.controller.contentWindow.postMessage({type:"method-change",channel:l},this.frameUrl)}setAutoAdvance(e){e.enabled&&(A(c.AUTO_ADVANCE_ENABLED),this.autoAdvance=(e=>{var t=e.enabled,r=e.secureFields,n=(e=>{if(!(null==e?void 0:e.length))return b;var t=e.filter(((t,r)=>b.includes(t)&&e.indexOf(t)===r)),r=b.filter((e=>!t.includes(e)));return[...t,...r]})(e.fieldOrder),i=e=>e?"number"===e?r.cardNumber:"expiryDate"===e?r.expiryDate:"securityCode"===e?r.securityCode:r.otherFields[e]:null,o=e=>{var t=e.type,r=e.nextIndex,a=null!=r?r:n.indexOf(t);if(!(a<0||a>=n.length-1)){var s=i(n[a+1]);!(null==s?void 0:s.complete)&&(null==s?void 0:s.frame)?s.focus():o({nextIndex:a+1})}};return{get enabled(){return t},get fieldOrder(){return n},updateEnterKeyHint:e=>{var r;if(null==e?void 0:e.frame){var o=n.indexOf(e.type),a=n[o+1],s=a&&(null===(r=i(a))||void 0===r?void 0:r.frame);e.setEnterKeyHint(t&&s?"next":"done")}},trigger:o}})(X($({},e),{secureFields:this})))}_addField(e,t,r){if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var n=e.closest("[data-secure-fields-input-group]"),i=null!=n?n:document.createElement("div"),o=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":y.publish("".concat(t.type,":blur"),e.data.data),i.removeAttribute(s.FOCUSED),T("Field blurred",e.data.data);break;case"focus":y.publish("".concat(t.type,":focus"),e.data.data),i.setAttribute(s.FOCUSED,""),T("Field focused",e.data.data);break;case"input":var n,o=e.data.data,a=o.complete,c=o.fromBlur,l=o.isDeleteInputType,d=ee(o,["complete","fromBlur","isDeleteInputType"]);if(y.publish("".concat(t.type,":input"),d),t.complete=a,e.data.data.valid?i.removeAttribute(s.INVALID):i.setAttribute(s.INVALID,""),e.data.data.autofilled?i.setAttribute(s.AUTOFILLED,""):i.removeAttribute(s.AUTOFILLED),(null===(n=this.autoAdvance)||void 0===n?void 0:n.enabled)&&a&&!d.autofilled&&!1===c&&!l&&this.autoAdvance.trigger({type:t.type}),this.schemeIcons&&"number"===t.type){var h,u,p;d.bin||(this.cardDetailsSchemes={scheme:void 0,additionalSchemes:[]});var m=null!==(h=null===(u=this.cardDetailsSchemes)||void 0===u?void 0:u.scheme)&&void 0!==h?h:d.schema,f=null===(p=this.cardDetailsSchemes)||void 0===p?void 0:p.additionalSchemes;!m&&d.empty&&this.schemeIcons.config.placeholders?this.schemeIcons.showPlaceholders():m?this.schemeIcons.showSchemes({scheme:m,additionalSchemes:f}):this.schemeIcons.hideSchemes()}T("Field input changed",d);break;case"redacted":y.publish("".concat(t.type,":redacted"),e.data.data),T("Field redacted",e.data.data);break;case"unredacted":y.publish("".concat(t.type,":unredacted"),e.data.data),T("Field unredacted",e.data.data);break;case"card-details-changed":var v;y.publish("".concat(t.type,":card-details-changed"),e.data.data),this.schemeIcons&&(this.cardDetailsSchemes={scheme:e.data.data.scheme,additionalSchemes:null!==(v=e.data.data.additionalSchemes)&&void 0!==v?v:[]},this.schemeIcons.showSchemes(this.cardDetailsSchemes)),T("Card details changed",e.data.data)}};return v.remove("message",o,t.type),v.add("message",o,t.type),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,this.controllerReady.then((()=>{var o,a,s,c;o=e,a=i,Array.from(o.attributes).forEach((e=>{var t=e.name,r=e.value;_.some((e=>new RegExp(e).test(t)))&&a.setAttribute(t,r)})),(i=a).classList.add("secure-fields__input","secure-fields__input--".concat(w(t.type))),n?(null===(s=e.parentNode)||void 0===s||s.replaceChild(t.frame,e),n.style.display="inline-flex",n.style.alignItems="center",t.frame.style.minWidth="0"):(null===(c=e.parentNode)||void 0===c||c.replaceChild(i,e),i.appendChild(t.frame)),"number"===t.type&&(null==r?void 0:r.showSchemeIcons)&&(i.style.display="inline-flex",i.style.alignItems="center",this.schemeIcons=(e=>{var t=e.baseUrl,r=(e=>{var t={scheme:!1,additionalSchemes:!1,placeholders:!1};return"boolean"==typeof e?e?{scheme:!0,additionalSchemes:!0,placeholders:!1}:t: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){P(e,t,r[t])}))}return e}({},t,e)})(e.showSchemeIcons),n=new Set,i=document.createElement("div");i.classList.add("secure-fields__scheme-icons"),i.style.display="flex",i.style.gap="4px",i.style.marginRight="4px";var o=Array.from({length:3},(()=>{var e=document.createElement("img");return e.setAttribute("alt",""),e.setAttribute("aria-hidden","true"),e.style.display="none",e.onerror=()=>{var t=e.getAttribute("src");t&&n.add(t),e.style.display="none"},e.onload=()=>{e.style.display="block"},i.appendChild(e),e})),a=e=>{var i=e.scheme,a=void 0===i?"":i,s=e.additionalSchemes,c=void 0===s?[]:s,l=e.placeholders,d=void 0!==l&&l,h=[...r.scheme&&a?[a]:[],...r.additionalSchemes&&c.length?c:[],...d?S:[]].slice(0,3);o.forEach(((e,r)=>{var i=h[r];if(i){var o="".concat(t,"/").concat(i,".svg");e.getAttribute("src")!==o?(e.setAttribute("src",o),e.width=48):n.has(o)||(e.style.display="block")}else e.style.display="none"}))};return{config:r,container:i,slots:o,showSchemes:a,showPlaceholders:()=>a({placeholders:!0}),hideSchemes:()=>o.forEach((e=>e.style.display="none"))}})({baseUrl:"".concat(this.cdnBaseUrl,"/assets/icons/card-schemes"),showSchemeIcons:r.showSchemeIcons}),t.frame.after(this.schemeIcons.container),this.schemeIcons.config.placeholders&&this.schemeIcons.showPlaceholders()),t._resolveReady(),t.frame.addEventListener("load",(()=>{var e;return null===(e=this.autoAdvance)||void 0===e?void 0:e.updateEnterKeyHint(t)}))})),t}addCardNumberField(e,t){return this.paymentMethodId&&A(c.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new Z(X($({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{}),{options:X($({label:"Card number"},t),{type:"number"})}))),this._addField(e,this.cardNumber,t)}addSecurityCodeField(e,t){var r,n;return this.securityCode||(this.securityCode=new Z({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:X($({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&&A(c.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new Z({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:X($({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addField(e,t){if(["number","expiryDate","securityCode"].includes(t.type)){t.pattern&&A(c.FIELD_PATTERN_IN_USE,$({method:"addField"},t)),t.pattern,t.type;var r=ee(t,["pattern","type"]);return this[d[t.type]](e,r)}return this.otherFields[t.type]||(this.otherFields=X($({},this.otherFields),{[t.type]:new Z({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 j(this),this.threeDS.init(e,t))}addClickToPay(e,t){return(r=function*(){if(!this.paymentMethodId)return this.clickToPayInstance=yield new V(this),this.clickToPay=yield this.clickToPayInstance.init(e,t),this.clickToPay;A(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){Q(o,n,i,a,s,"next",e)}function s(e){Q(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===Z?"".concat(r,":"):"").concat(e);y.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===Z?"".concat(r,":"):"").concat(e);y.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;y.publish(o.CARD_VAULT_SUCCESS,e.data.data),(null===(s=e.data.data)||void 0===s?void 0:s.warn)&&(A(e.data.data.warn),delete e.data.data.warn),T("Payment method tokenized successfully",e.data.data);break;case"error":y.publish(o.CARD_VAULT_FAILURE,e.data),T("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,i;J(this,"config",void 0),J(this,"controller",void 0),J(this,"frameUrl",void 0),J(this,"apiUrl",void 0),J(this,"cdnBaseUrl",void 0),J(this,"parentOrigin",void 0),J(this,"font",void 0),J(this,"cardNumber",void 0),J(this,"securityCode",void 0),J(this,"expiryDate",void 0),J(this,"otherFields",{}),J(this,"method","card"),J(this,"clickToPayInstance",void 0),J(this,"clickToPay",void 0),J(this,"threeDS",void 0),J(this,"environmentPath",void 0),J(this,"paymentMethodId",void 0),J(this,"autoAdvance",null),J(this,"schemeIcons",null),J(this,"cardDetailsSchemes",null),J(this,"controllerReady",void 0),J(this,"_resolveControllerReady",void 0),y.unsubscribeAll(),this.config=$({environment:"production"},e),this.controllerReady=new Promise((e=>{var t=Date.now();this._resolveControllerReady=()=>e(Date.now()-t)})),this.config.paymentMethodId&&!this.config.paymentMethod&&A(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,this.cdnBaseUrl=function(e){return r(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production","cdn")}(this.config.gr4vyId,this.config.environment);var a=$({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.paymentMethodId?{paymentMethodId:this.paymentMethodId}:{});null===(i=document.body.querySelector("iframe#controller[src*=secure-fields]"))||void 0===i||i.remove(),this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=n("".concat(this.frameUrl,"/controller.html"),a),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 Z,this.expiryDate=new Z),T("Initialized",X($({},this.config),{version:te.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin}));var s=e=>{if(e.origin===this.frameUrl)switch(e.data.type){case"ready":var t=$({version:te.version},this.config);y.publish(o.READY,t),this._resolveControllerReady(),T("Ready",t);break;case"form-change":y.publish(o.FORM_CHANGE,e.data.data),T("Form change",e.data.data)}};v.remove("message",s,"init"),v.add("message",s,"init"),this.controllerReady.then((e=>T("Loaded controller after ".concat(e," milliseconds"))))}}return t})()));
|
package/lib/types.d.ts
CHANGED
|
@@ -43,7 +43,11 @@ export type Field = {
|
|
|
43
43
|
size?: number;
|
|
44
44
|
autoFocus?: boolean;
|
|
45
45
|
maskInput?: boolean | FieldMaskConfig;
|
|
46
|
-
showSchemeIcons?: boolean
|
|
46
|
+
showSchemeIcons?: boolean | {
|
|
47
|
+
scheme?: boolean;
|
|
48
|
+
additionalSchemes?: boolean;
|
|
49
|
+
placeholders?: boolean;
|
|
50
|
+
};
|
|
47
51
|
};
|
|
48
52
|
export type FieldEventType = keyof HTMLElementEventMap | 'redacted' | 'unredacted' | 'card-details-changed';
|
|
49
53
|
export type FieldEvent = {
|
|
@@ -55,6 +59,7 @@ export type FieldEvent = {
|
|
|
55
59
|
empty: boolean;
|
|
56
60
|
schema?: string;
|
|
57
61
|
scheme?: string;
|
|
62
|
+
additionalSchemes?: string[];
|
|
58
63
|
bin?: string;
|
|
59
64
|
complete?: boolean;
|
|
60
65
|
fromBlur?: boolean;
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
export declare const createSchemeIcons: ({ baseUrl }: {
|
|
1
|
+
export declare const createSchemeIcons: ({ baseUrl, showSchemeIcons, }: {
|
|
2
2
|
baseUrl: string;
|
|
3
|
+
showSchemeIcons: boolean | {
|
|
4
|
+
scheme?: boolean;
|
|
5
|
+
additionalSchemes?: boolean;
|
|
6
|
+
placeholders?: boolean;
|
|
7
|
+
};
|
|
3
8
|
}) => {
|
|
9
|
+
config: {
|
|
10
|
+
scheme: boolean;
|
|
11
|
+
additionalSchemes: boolean;
|
|
12
|
+
placeholders: boolean;
|
|
13
|
+
};
|
|
4
14
|
container: HTMLDivElement;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
slots: HTMLImageElement[];
|
|
16
|
+
showSchemes: ({ scheme: _scheme, additionalSchemes: _additionalSchemes, placeholders, }: {
|
|
17
|
+
scheme?: string;
|
|
18
|
+
additionalSchemes?: any[];
|
|
19
|
+
placeholders?: boolean;
|
|
20
|
+
}) => void;
|
|
21
|
+
showPlaceholders: () => void;
|
|
22
|
+
hideSchemes: () => void;
|
|
9
23
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gr4vy/secure-fields",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.1",
|
|
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",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"lint": "eslint ./src --ext ts",
|
|
38
38
|
"prebuild": "yarn clean",
|
|
39
39
|
"prepack": "yarn build",
|
|
40
|
-
"test": "
|
|
40
|
+
"test": "yarn test:unit",
|
|
41
|
+
"test:unit": "jest --colors",
|
|
41
42
|
"token": "node generate-token",
|
|
42
43
|
"watch": "webpack watch --config webpack.prod.js"
|
|
43
44
|
},
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"css-loader": "^6.11.0",
|
|
46
47
|
"csstype": "^3.2.3",
|
|
47
48
|
"dotenv": "^16.6.1",
|
|
48
|
-
"msw": "^2.
|
|
49
|
+
"msw": "^2.14.6",
|
|
49
50
|
"style-loader": "^3.3.4",
|
|
50
51
|
"ts-patch": "^3.3.0",
|
|
51
52
|
"typedoc": "^0.28.19",
|
|
@@ -56,5 +57,5 @@
|
|
|
56
57
|
"access": "public",
|
|
57
58
|
"registry": "https://registry.npmjs.org"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "83a98fd6f3322aaa7229e49ae89671b4453cfde4"
|
|
60
61
|
}
|