@gr4vy/secure-fields 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,36 @@
1
+ # v1.14.0 (Thu Nov 09 2023)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - feat: stored payment method [#499](https://github.com/gr4vy/secure-fields/pull/499) ([@luca-gr4vy](https://github.com/luca-gr4vy) [@cbetta](https://github.com/cbetta))
6
+
7
+ #### 🐛 Bug Fix
8
+
9
+ - feat(click-to-pay): trigger change when the method has actually changed [#494](https://github.com/gr4vy/secure-fields/pull/494) ([@douglaseggleton](https://github.com/douglaseggleton))
10
+ - feat: optional src dpa id/name [#492](https://github.com/gr4vy/secure-fields/pull/492) ([@douglaseggleton](https://github.com/douglaseggleton))
11
+ - fix: C2P learn more [#485](https://github.com/gr4vy/secure-fields/pull/485) ([@luca-gr4vy](https://github.com/luca-gr4vy))
12
+ - fix: skip C2P when checkbox is not selected [#480](https://github.com/gr4vy/secure-fields/pull/480) ([@luca-gr4vy](https://github.com/luca-gr4vy))
13
+ - task: allow C2P to work with an email/phone number [#474](https://github.com/gr4vy/secure-fields/pull/474) ([@luca-gr4vy](https://github.com/luca-gr4vy))
14
+ - task: enable C2P consent checkbox [#473](https://github.com/gr4vy/secure-fields/pull/473) ([@luca-gr4vy](https://github.com/luca-gr4vy))
15
+ - fix: C2P learn more [#462](https://github.com/gr4vy/secure-fields/pull/462) ([@luca-gr4vy](https://github.com/luca-gr4vy))
16
+ - fix: clear consent checkbox on an unknown error [TA-5154] [#456](https://github.com/gr4vy/secure-fields/pull/456) ([@thomas-gr4vy](https://github.com/thomas-gr4vy))
17
+
18
+ #### 🏠 Internal
19
+
20
+ - chore(dev-deps): update dependency typedoc to ^0.25.3 [#489](https://github.com/gr4vy/secure-fields/pull/489) ([@renovate[bot]](https://github.com/renovate[bot]))
21
+ - chore(dev-deps): update dependency typedoc-plugin-missing-exports to ^2.1.0 [#469](https://github.com/gr4vy/secure-fields/pull/469) ([@renovate[bot]](https://github.com/renovate[bot]))
22
+ - chore(dev-deps): update dependency typedoc to ^0.25.2 [#460](https://github.com/gr4vy/secure-fields/pull/460) ([@renovate[bot]](https://github.com/renovate[bot]))
23
+
24
+ #### Authors: 5
25
+
26
+ - [@renovate[bot]](https://github.com/renovate[bot])
27
+ - Cristiano Betta ([@cbetta](https://github.com/cbetta))
28
+ - Douglas Eggleton ([@douglaseggleton](https://github.com/douglaseggleton))
29
+ - Luca Allievi ([@luca-gr4vy](https://github.com/luca-gr4vy))
30
+ - Thomas ([@thomas-gr4vy](https://github.com/thomas-gr4vy))
31
+
32
+ ---
33
+
1
34
  # v1.13.0 (Thu Oct 05 2023)
2
35
 
3
36
  #### 🐛 Bug Fix
package/README.md CHANGED
@@ -33,7 +33,7 @@ To use Secure Fields, you need some placeholder elements to attach the secure fi
33
33
  <button id="cc-button">Submit</button>
34
34
  ```
35
35
 
36
- To use Secure Fields, call the `new SecureFields()` method with a configuration object that includes the `environment` (`sandbox` or `production`), your `gr4vyId` and a `sessionId` obtained from calling the [Checkout Sessions API](https://gr4vy.com/docs/reference#tag/Checkout-Sessions).
36
+ To use Secure Fields, call the `new SecureFields()` method with a configuration object that includes the `environment` (`sandbox` or `production`), your `gr4vyId` and a `sessionId` obtained from calling the [Checkout Sessions API](https://gr4vy.com/docs/reference#tag/Checkout-Sessions). An optional `paymentMethodId` parameter can also be passed to use Secure Fields with a stored payment method.
37
37
 
38
38
  Then, add the fields and event listeners needed to handle the form submission.
39
39
 
@@ -47,6 +47,7 @@ const secureFields = new SecureFields({
47
47
  gr4vyId: '[GR4VY_ID]',
48
48
  environment: 'sandbox',
49
49
  sessionId: '[SESSION_ID]',
50
+ // paymentMethodId: '[PAYMENT_METHOD_ID]', // uuid of a stored payment method (optional)
50
51
  })
51
52
 
52
53
  secureFields.addFont('Lato')
@@ -219,7 +220,7 @@ Some of these provide additional useful data like the card BIN, validation statu
219
220
 
220
221
  | Name | Description |
221
222
  | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
222
- | `constructor` | Instantiates SecureFields with a configuration object include `environment`, `gr4vyId` and a session id. <br /><br />`new SecureFields({...})` |
223
+ | `constructor` | Instantiates SecureFields with a configuration object include `environment`, `gr4vyId` and a session id. An optional `paymentMethodId` parameter can also be passed to use Secure Fields with a stored payment method. <br /><br />`new SecureFields({...})` |
223
224
  | `addCardNumberField` | Injects a secure field of type `number`. <br /><br />`secureFields.addCardNumberField('#cc-number', { placeholder: 'Enter card number', ... })` |
224
225
  | `addSecurityCodeField` | Injects a secure field of type `securityCode`. <br /><br />`secureFields.addSecurityCodeField('#cc-security-code', { placeholder: 'Enter security code', ... })` |
225
226
  | `addExpiryDateField` | Injects a secure field of type `expiryDate`. <br /><br />`secureFields.addExpiryDateField('#cc-expiry-date', { placeholder: 'Enter expiry date', ... })` |
@@ -6,10 +6,13 @@ export declare enum Events {
6
6
  METHOD_CHANGE = "method-change",
7
7
  READY = "ready",
8
8
  RESIZE = "resize",
9
+ CLICK_TO_PAY_INITIALIZED = "click-to-pay-initialized",
9
10
  CLICK_TO_PAY_READY = "click-to-pay-ready",
10
11
  CLICK_TO_PAY_SIGN_OUT = "click-to-pay-sign-out",
11
12
  CLICK_TO_PAY_ERROR = "click-to-pay-error",
12
- CLICK_TO_PAY_CANCEL = "click-to-pay-cancel"
13
+ CLICK_TO_PAY_CANCEL = "click-to-pay-cancel",
14
+ CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD = "click-to-pay-checkout-with-new-card",
15
+ CLICK_TO_PAY_UNABLE_TO_LOAD_DPA = "click-to-pay-unable-to-load-dpa"
13
16
  }
14
17
  export declare enum ClickToPayInternalEvents {
15
18
  REQUEST_PORT = "request-port",
@@ -20,4 +23,7 @@ export declare enum FieldAttributes {
20
23
  INVALID = "data-secure-fields-invalid",
21
24
  AUTOFILLED = "data-secure-fields-autofilled"
22
25
  }
26
+ export declare enum LogMessages {
27
+ 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"
28
+ }
23
29
  export declare const MESSAGE_CHANNEL = "secure-fields";
@@ -0,0 +1,10 @@
1
+ export declare class UnableToLoadDpaError extends Error {
2
+ constructor(message: any);
3
+ }
4
+ export declare function fetchClickToPayDpa({ apiBaseUrl, checkoutSessionId, }: {
5
+ apiBaseUrl: string;
6
+ checkoutSessionId: string;
7
+ }): Promise<{
8
+ srcDpaId: string;
9
+ dpaName: string;
10
+ }>;
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.d.ts CHANGED
@@ -40,8 +40,8 @@ declare class SecureFields {
40
40
  addSecurityCodeField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
41
41
  addExpiryDateField(element: string | HTMLElement, options?: Omit<Field, 'element' | 'type'>): SecureInput;
42
42
  addClickToPay(element: string | HTMLElement, options?: {
43
- srcDpaId: string;
44
- dpaName: string;
43
+ srcDpaId?: string;
44
+ dpaName?: string;
45
45
  cardBrands: Array<'mastercard' | 'maestro' | 'visa' | 'amex' | 'discover'>;
46
46
  dpaLocale: string;
47
47
  cardForm?: string | HTMLElement;
@@ -54,7 +54,7 @@ declare class SecureFields {
54
54
  countryCode: string;
55
55
  phoneNumber: string;
56
56
  };
57
- })): void;
57
+ })): Promise<void>;
58
58
  addEventListener(event: CombinedEvents, callback: (...args: any[]) => void): void;
59
59
  removeEventListener(event: CombinedEvents, callback: (...args: any[]) => void): void;
60
60
  submit(): void;
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(function(){return function(){"use strict";var e={d:function(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:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(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,{SecureFields:function(){return _},SecureInput:function(){return O}});var r,n,o,i="@gr4vy-secure-fields-debug";!function(e){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_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"}(r||(r={})),function(e){e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port"}(n||(n={})),function(e){e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled"}(o||(o={}));var a="secure-fields";function s(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 c(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,o,i=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){s=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(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)?s(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 l=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=c(r,2),o=n[0],i=n[1];return o!==e||i.toString()!==t.toString()}))}publish(e,t){this.subscribers.forEach((r=>{var n=c(r,2),o=n[0],i=n[1];return setTimeout((()=>o===e?i(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=[]}},d=["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"];function u(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var h={debug:!1,level:"log"},p=(e,t,r)=>{var n=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){u(e,t,r[t])}))}return e}({},h,r),o=n.debug,a=n.level;(o||"true"===localStorage.getItem(i))&&console[a]("Gr4vy - Secure Fields - ".concat(e),t||{})},f=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var b=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,o)=>{var i,a,s=(a=2,function(e){if(Array.isArray(e))return e}(i=o)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){s=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw o}}return i}}(i,a)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}(i,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=f(c).replace(/^-/,""),n.push(["--".concat(r).concat(c),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};function m(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function 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){m(e,t,r[t])}))}return e}function v(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class O{_postMessage(e){this.frame.contentWindow.postMessage(g({channel:a},e),this.frameUrl)}update(e){this.options=g({},this.options,e);var t=b(g({},this.options.styles,e.styles)),r=v(g({},this.options,e),{styles:t});this._postMessage({type:"update",data:v(g({},r),{styles:t})}),p("Updated field",this.options)}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){m(this,"frameUrl",void 0),m(this,"parentOrigin",void 0),m(this,"frame",void 0),m(this,"type",void 0),m(this,"options",void 0),m(this,"addEventListener",void 0),m(this,"removeEventListener",void 0);var t=e.frameUrl,r=e.parentOrigin,n=e.font,o=e.options.type,i=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e.options,["type"]);this.frameUrl=t,this.parentOrigin=r,this.type=o,this.options=i;var a=b(i.styles);this.frame=document.createElement("iframe"),this.frame.id=o,this.frame.src="".concat(t,"/input.html?parentOrigin=").concat(r,"&type=").concat(this.type),this.frame.style.display="block",this.frame.style.height="100%",this.frame.style.border="none",this.frame.style.width="100%",n&&(this.frame.src+="&font=".concat(n)),this.frame.onload=()=>{this._postMessage({type:"update",data:v(g({},this.options),{styles:a})}),p("Added field",this.options)}}}function w(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function 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){w(e,t,r[t])}))}return e}function E(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class _{static get Events(){return r}static get version(){return"#d7d3191e8c52329983e2e0bcf19e24f406b7f5a2"}_addField(e,t){if(!(e="string"==typeof e?document.querySelector(e):e))return t;var r,n,i=document.createElement("div");return r=e,n=i,Array.from(r.attributes).forEach((e=>{var t=e.name,r=e.value;d.some((e=>new RegExp(e).test(t)))&&n.setAttribute(t,r)})),(i=n).classList.add("secure-fields__input","secure-fields__input--".concat(f(t.type))),i.appendChild(t.frame),e.parentNode.replaceChild(i,e),window.addEventListener("message",(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":l.publish("".concat(t.type,":blur"),e.data.data),i.removeAttribute(o.FOCUSED),p("Field blurred",e.data.data);break;case"focus":l.publish("".concat(t.type,":focus"),e.data.data),i.setAttribute(o.FOCUSED,""),p("Field focused",e.data.data);break;case"input":l.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?i.removeAttribute(o.INVALID):i.setAttribute(o.INVALID,""),e.data.data.autofilled?i.setAttribute(o.AUTOFILLED,""):i.removeAttribute(o.AUTOFILLED),p("Field input changed",e.data.data)}})),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.cardNumber||(this.cardNumber=new O({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:E(C({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){return this.securityCode||(this.securityCode=new O({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:E(C({label:"Security code"},t),{type:"securityCode"})})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.expiryDate||(this.expiryDate=new O({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:E(C({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addClickToPay(e,t){this.clickToPayUrl=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(this.environmentPath).concat(this.config.gr4vyId,".gr4vy.app"),this.parentOrigin=window.location.origin,this.clickToPayOrigin=new URL(this.clickToPayUrl).origin,t.cardForm;var o=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,["cardForm"]),i=C({gr4vyId:this.config.gr4vyId,environment:this.config.environment,sessionId:this.config.sessionId},o),s=document.createElement("iframe");s.setAttribute("width","100%"),s.setAttribute("frameborder","0"),s.setAttribute("style","height:0px"),s.src="".concat(this.clickToPayUrl,"/click-to-pay.html?parentOrigin=").concat(this.parentOrigin,"&environment=").concat(this.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(i)));var c=document.createElement("iframe");c.setAttribute("width","0"),c.setAttribute("frameborder","0"),c.setAttribute("style","height:0px"),c.src="".concat(this.frameUrl,"/click-to-pay-encrypt.html?parentOrigin=").concat(this.parentOrigin,"&environment=").concat(this.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(i)));var d=new MessageChannel;if(window.addEventListener("message",(e=>{switch(e.origin){case this.clickToPayOrigin:switch(e.data.type){case r.RESIZE:s.style.height=e.data.data.height>0?"".concat(e.data.data.height+48,"px"):"0px";break;case r.METHOD_CHANGE:this.method=e.data.data.method||"card",l.publish(r.METHOD_CHANGE,e.data.data),p("Method changed",{method:this.method}),this.controller.contentWindow.postMessage({type:"method-change",channel:a},this.frameUrl);break;case r.CLICK_TO_PAY_READY:l.publish(r.CLICK_TO_PAY_READY),p("Click to Pay ready");break;case r.CLICK_TO_PAY_SIGN_OUT:l.publish(r.CLICK_TO_PAY_SIGN_OUT),p("Click to pay signed out");break;case r.CLICK_TO_PAY_ERROR:l.publish(r.CLICK_TO_PAY_ERROR,e.data.data),p("Click to Pay error:",e.data.data);break;case r.CLICK_TO_PAY_CANCEL:l.publish(r.CLICK_TO_PAY_CANCEL,e.data.data),p("Click to Pay cancelled");break;case n.REQUEST_PORT:s.contentWindow.postMessage({channel:a,type:n.TRANSFER_PORT},this.clickToPayOrigin,[d.port1])}break;case this.frameUrl:e.data.type===n.REQUEST_PORT&&c.contentWindow.postMessage({channel:a,type:n.TRANSFER_PORT},this.frameUrl,[d.port2])}})),null==t?void 0:t.consentCheckbox){var u="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;this.method=u.checked?"click-to-pay":"card",p("Method changed",{method:this.method}),u.setAttribute("disabled","disabled"),window.addEventListener("message",(e=>{e.data.type===r.CLICK_TO_PAY_READY&&(u.removeAttribute("disabled"),u.addEventListener("change",(e=>{var t=e.target;this.clickToPayConsent=t.checked})))}))}if(null==t?void 0:t.learnMoreLink){var h="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;h.style.visibility="hidden",window.addEventListener("message",(e=>{e.data.type===r.CLICK_TO_PAY_READY&&(h.style.visibility="visible",h.addEventListener("click",(()=>{s.contentWindow.postMessage({type:"show-learn-more",channel:a},this.frameUrl)})))}))}(e="string"==typeof e?document.querySelector(e):e).appendChild(s),e.appendChild(c),this.clickToPayController=s}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===O?"".concat(r,":"):"").concat(e);l.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===O?"".concat(r,":"):"").concat(e);l.unsubscribe(n,t)}submit(){var e=t=>{var n=[this.frameUrl,this.clickToPayOrigin].includes(t.origin),o=t.data.channel===a,i=["success","error"].includes(t.data.type);if(n&&o&&i){switch(t.data.type){case"success":l.publish(r.CARD_VAULT_SUCCESS),p("Payment method tokenized successfully");break;case"error":l.publish(r.CARD_VAULT_FAILURE,t.data),p("Failed to update checkout session",t.data.data)}window.removeEventListener("message",e)}};window.addEventListener("message",e),"click-to-pay"===this.method||"card"===this.method&&!0===this.clickToPayConsent?this.clickToPayController.contentWindow.postMessage({type:"submit",channel:a},this.clickToPayUrl):this.controller.contentWindow.postMessage({type:"submit",channel:a},this.frameUrl)}setDebug(e){localStorage.setItem(i,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){w(this,"config",void 0),w(this,"controller",void 0),w(this,"frameUrl",void 0),w(this,"apiUrl",void 0),w(this,"parentOrigin",void 0),w(this,"font",void 0),w(this,"cardNumber",void 0),w(this,"securityCode",void 0),w(this,"expiryDate",void 0),w(this,"method","card"),w(this,"clickToPayController",void 0),w(this,"clickToPayUrl",void 0),w(this,"clickToPayOrigin",void 0),w(this,"environmentPath",void 0),w(this,"clickToPayConsent",!1),this.config=C({environment:"production"},e),this.environmentPath="sandbox"===this.config.environment?"sandbox.":"",this.frameUrl=window.SECURE_FIELDS_FRAME_URL||"https://secure-fields.".concat(this.environmentPath).concat(this.config.gr4vyId,".gr4vy.app"),this.parentOrigin=window.location.origin,this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src="".concat(this.frameUrl,"/controller.html?parentOrigin=").concat(this.parentOrigin,"&sessionId=").concat(this.config.sessionId,"&gr4vyId=").concat(this.config.gr4vyId,"&environment=").concat(this.config.environment),this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),window.onload=()=>{l.publish(r.READY,C({version:_.version},this.config))},p("Initialized",E(C({},this.config),{version:_.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin})),window.addEventListener("message",(e=>{e.origin===this.frameUrl&&"form-change"===e.data.type&&(l.publish(r.FORM_CHANGE,e.data.data),p("Form change",e.data.data))}))}}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,(function(){return function(){"use strict";var e={d:function(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:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r,n,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,o)}e.r(t),e.d(t,{SecureFields:function(){return L},SecureInput:function(){return I}});class n extends Error{constructor(e){super(e),this.name="UnableToLoadDpaError"}}function o(){var e;return e=function*(e){var t=e.apiBaseUrl,r=e.checkoutSessionId;try{var o="".concat(t,"/digital-wallets/click-to-pay/session"),i=yield fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({checkout_session_id:r})});if(i.ok){var a=yield i.json();return{srcDpaId:a.digital_payment_application_id,dpaName:a.digital_payment_application_name}}throw new n("Unable to load DPA")}catch(e){throw new n("Unable to load DPA")}},o=function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function c(e){r(a,o,i,c,s,"next",e)}function s(e){r(a,o,i,c,s,"throw",e)}c(void 0)}))},o.apply(this,arguments)}var i,a,c,s,l="@gr4vy-secure-fields-debug";!function(e){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"}(i||(i={})),function(e){e.REQUEST_PORT="request-port",e.TRANSFER_PORT="transfer-port"}(a||(a={})),function(e){e.FOCUSED="data-secure-fields-focused",e.INVALID="data-secure-fields-invalid",e.AUTOFILLED="data-secure-fields-autofilled"}(c||(c={})),function(e){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"}(s||(s={}));var d="secure-fields";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,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(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 h=new class{subscribe(e,t){this.subscribers.push([e,t])}unsubscribe(e,t){this.subscribers=this.subscribers.filter((r=>{var n=p(r,2),o=n[0],i=n[1];return o!==e||i.toString()!==t.toString()}))}publish(e,t){this.subscribers.forEach((r=>{var n=p(r,2),o=n[0],i=n[1];return setTimeout((()=>o===e?i(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=[]}},y=["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"];function f(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){f(e,t,r[t])}))}return e}var b={debug:!1,level:"log"},g=(e,t,r)=>{var n=m({},b,r),o=n.debug,i=n.level;(o||"true"===localStorage.getItem(l))&&console[i]("Gr4vy - Secure Fields - ".concat(e),t||{})},v=(e,t,r)=>{var n,o;g(e,t,(n=m({},r),o=null!=(o={level:"warn"})?o:{},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(o)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))})),n))},O=e=>(e!=e.toLowerCase()&&(e=e.replace(/[A-Z]/g,(e=>"-"+e.toLowerCase()))),e);function _(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 C=function(){var e=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.entries(t).reduce(((n,o)=>{var i,a,c=(a=2,function(e){if(Array.isArray(e))return e}(i=o)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}}(i,a)||function(e,t){if(e){if("string"==typeof e)return _(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)?_(e,t):void 0}}(i,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.")}()),s=c[0],l=c[1];return(e=>"[object Object]"===Object.prototype.toString.call(e))(l)?n.push(...e(t[s],"".concat((r+s).match(/[a-zA-Z0-9]+/g).join("-"),"-"))):(s=O(s).replace(/^-/,""),n.push(["--".concat(r).concat(s),l])),n}),[])};return e(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})};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}function E(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}function w(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class I{_postMessage(e){this.frame.contentWindow.postMessage(E({channel:d},e),this.frameUrl)}update(e){if(this.frameUrl){this.options=E({},this.options,e);var t=C(E({},this.options.styles,e.styles)),r=w(E({},this.options,e),{styles:t});this._postMessage({type:"update",data:w(E({},r),{styles:t})}),g("Updated field",this.options)}}setPlaceholder(e){this.update({placeholder:e})}setStyles(e){this.update({styles:e})}constructor(e){if(P(this,"frameUrl",void 0),P(this,"parentOrigin",void 0),P(this,"frame",void 0),P(this,"type",void 0),P(this,"options",void 0),P(this,"addEventListener",void 0),P(this,"removeEventListener",void 0),e){var t=e.frameUrl,r=e.parentOrigin,n=e.font,o=e.options.type,i=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e.options,["type"]);this.frameUrl=t,this.parentOrigin=r,this.type=o,this.options=i;var a=C(i.styles);this.frame=document.createElement("iframe"),this.frame.id=o,this.frame.src="".concat(t,"/input.html?parentOrigin=").concat(r,"&type=").concat(this.type),this.frame.style.display="block",this.frame.style.height="100%",this.frame.style.border="none",this.frame.style.width="100%",n&&(this.frame.src+="&font=".concat(n)),this.frame.onload=()=>{this._postMessage({type:"update",data:w(E({},this.options),{styles:a})}),g("Added field",this.options)}}}}function A(e,t,r,n,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,o)}function T(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}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){T(e,t,r[t])}))}return e}function S(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r.push.apply(r,n)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}class L{static get Events(){return i}static get version(){return"#9df00728263ae3bb495c2619521b70bbc004013e"}_addField(e,t){if(!(e="string"==typeof e?document.querySelector(e):e)||!t.frame)return t.addEventListener=()=>{},t.removeEventListener=()=>{},t;var r,n,o=document.createElement("div");return r=e,n=o,Array.from(r.attributes).forEach((e=>{var t=e.name,r=e.value;y.some((e=>new RegExp(e).test(t)))&&n.setAttribute(t,r)})),(o=n).classList.add("secure-fields__input","secure-fields__input--".concat(O(t.type))),o.appendChild(t.frame),e.parentNode.replaceChild(o,e),window.addEventListener("message",(e=>{var r;if(e.origin===this.frameUrl&&(null===(r=e.data.data)||void 0===r?void 0:r.id)===t.type)switch(e.data.type){case"blur":h.publish("".concat(t.type,":blur"),e.data.data),o.removeAttribute(c.FOCUSED),g("Field blurred",e.data.data);break;case"focus":h.publish("".concat(t.type,":focus"),e.data.data),o.setAttribute(c.FOCUSED,""),g("Field focused",e.data.data);break;case"input":h.publish("".concat(t.type,":input"),e.data.data),e.data.data.valid?o.removeAttribute(c.INVALID):o.setAttribute(c.INVALID,""),e.data.data.autofilled?o.setAttribute(c.AUTOFILLED,""):o.removeAttribute(c.AUTOFILLED),g("Field input changed",e.data.data)}})),t.addEventListener=this.addEventListener,t.removeEventListener=this.removeEventListener,t}addCardNumberField(e,t){return this.config.paymentMethodId&&v(s.PAYMENT_METHOD_ID_IN_USE,{method:"addCardNumberField"}),this.cardNumber||(this.cardNumber=new I({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:S(k({label:"Card number"},t),{type:"number"})})),this._addField(e,this.cardNumber)}addSecurityCodeField(e,t){return this.securityCode||(this.securityCode=new I({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:S(k({label:"Security code"},t),{type:"securityCode"})})),this._addField(e,this.securityCode)}addExpiryDateField(e,t){return this.config.paymentMethodId&&v(s.PAYMENT_METHOD_ID_IN_USE,{method:"addExpiryDateField"}),this.expiryDate||(this.expiryDate=new I({frameUrl:this.frameUrl,parentOrigin:this.parentOrigin,font:this.font,options:S(k({label:"Expiry date"},t),{type:"expiryDate"})})),this._addField(e,this.expiryDate)}addClickToPay(e,t){var r,n=this;return(r=function*(){if(n.config.paymentMethodId)v(s.PAYMENT_METHOD_ID_IN_USE,{method:"addClickToPay"});else{if(!(null==t?void 0:t.srcDpaId)||!(null==t?void 0:t.dpaName))try{var r=n.apiUrl||function(e){return"https://api.".concat("sandbox"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"production")?"sandbox.":"").concat(e,".gr4vy.app")}(n.config.gr4vyId,n.config.environment),c=yield function(e){return o.apply(this,arguments)}({apiBaseUrl:r,checkoutSessionId:n.config.sessionId}),l=c.srcDpaId,u=c.dpaName;t.srcDpaId=l,t.dpaName=u}catch(e){return g(e.message),void h.publish(i.CLICK_TO_PAY_UNABLE_TO_LOAD_DPA)}n.clickToPayUrl=window.CLICK_TO_PAY_FRAME_URL||"https://click-to-pay.".concat(n.environmentPath).concat(n.config.gr4vyId,".gr4vy.app"),n.parentOrigin=window.location.origin,n.clickToPayOrigin=new URL(n.clickToPayUrl).origin,t.cardForm;var p=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,["cardForm"]),y=k({gr4vyId:n.config.gr4vyId,environment:n.config.environment,sessionId:n.config.sessionId},p),f=document.createElement("iframe");f.setAttribute("width","100%"),f.setAttribute("frameborder","0"),f.setAttribute("style","height:0px"),f.src="".concat(n.clickToPayUrl,"/click-to-pay.html?parentOrigin=").concat(n.parentOrigin,"&environment=").concat(n.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(y)));var m=document.createElement("iframe");m.setAttribute("width","0"),m.setAttribute("frameborder","0"),m.setAttribute("style","height:0px"),m.src="".concat(n.frameUrl,"/click-to-pay-encrypt.html?parentOrigin=").concat(n.parentOrigin,"&environment=").concat(n.config.environment,"&config=").concat(encodeURIComponent(JSON.stringify(y)));var b=new MessageChannel,O=!0;if(window.addEventListener("message",(e=>{switch(e.origin){case n.clickToPayOrigin:switch(e.data.type){case i.RESIZE:f.style.height=e.data.data.height>0?"".concat(e.data.data.height+48,"px"):"0px";break;case i.METHOD_CHANGE:var t=e.data.data.method||"card";(n.method!==t||O)&&(O=!1,n.method=t,h.publish(i.METHOD_CHANGE,e.data.data),g("Method changed",{method:n.method}),n.controller.contentWindow.postMessage({type:"method-change",channel:d},n.frameUrl));break;case i.CLICK_TO_PAY_INITIALIZED:h.publish(i.CLICK_TO_PAY_INITIALIZED),g("Click to Pay initialized");break;case i.CLICK_TO_PAY_READY:h.publish(i.CLICK_TO_PAY_READY,e.data.data),g("Click to Pay ready");break;case i.CLICK_TO_PAY_SIGN_OUT:h.publish(i.CLICK_TO_PAY_SIGN_OUT),g("Click to pay signed out");break;case i.CLICK_TO_PAY_ERROR:h.publish(i.CLICK_TO_PAY_ERROR,e.data.data),g("Click to Pay error:",e.data.data);break;case i.CLICK_TO_PAY_CANCEL:h.publish(i.CLICK_TO_PAY_CANCEL,e.data.data),g("Click to Pay cancelled");break;case i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD:h.publish(i.CLICK_TO_PAY_CHECKOUT_WITH_NEW_CARD,e.data.data),g("Click to Pay checkout with new card initiated");break;case a.REQUEST_PORT:f.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},n.clickToPayOrigin,[b.port1])}break;case n.frameUrl:e.data.type===a.REQUEST_PORT&&m.contentWindow.postMessage({channel:d,type:a.TRANSFER_PORT},n.frameUrl,[b.port2])}})),null==t?void 0:t.consentCheckbox){var _="string"==typeof(null==t?void 0:t.consentCheckbox)?document.querySelector(null==t?void 0:t.consentCheckbox):null==t?void 0:t.consentCheckbox;n.method=_.checked?"click-to-pay":"card",g("Method changed",{method:n.method}),_.addEventListener("change",(e=>{var t=e.target;n.clickToPayConsent=t.checked})),window.addEventListener("message",(e=>{e.data.type===i.CLICK_TO_PAY_ERROR&&"UNKNOWN"===e.data.data.error&&(n.clickToPayConsent=!1,_.checked=!1)}))}if(null==t?void 0:t.learnMoreLink){var C="string"==typeof(null==t?void 0:t.learnMoreLink)?document.querySelector(null==t?void 0:t.learnMoreLink):null==t?void 0:t.learnMoreLink;C.style.visibility="hidden",window.addEventListener("message",(e=>{e.data.type===i.CLICK_TO_PAY_INITIALIZED&&(C.style.visibility="visible",C.addEventListener("click",(()=>{f.contentWindow.postMessage({type:"show-learn-more",channel:d},n.clickToPayOrigin)})))}))}(e="string"==typeof e?document.querySelector(e):e).appendChild(f),e.appendChild(m),n.clickToPayController=f}},function(){var e=this,t=arguments;return new Promise((function(n,o){var i=r.apply(e,t);function a(e){A(i,n,o,a,c,"next",e)}function c(e){A(i,n,o,a,c,"throw",e)}a(void 0)}))})()}addEventListener(e,t){var r=this.type,n="".concat(this.constructor===I?"".concat(r,":"):"").concat(e);h.subscribe(n,t)}removeEventListener(e,t){var r=this.type,n="".concat(this.constructor===I?"".concat(r,":"):"").concat(e);h.unsubscribe(n,t)}submit(){var e=t=>{var r=[this.frameUrl,this.clickToPayOrigin].includes(t.origin),n=t.data.channel===d,o=["success","error"].includes(t.data.type);if(r&&n&&o){switch(t.data.type){case"success":h.publish(i.CARD_VAULT_SUCCESS),g("Payment method tokenized successfully");break;case"error":h.publish(i.CARD_VAULT_FAILURE,t.data),g("Failed to update checkout session",t.data.data)}window.removeEventListener("message",e)}};window.addEventListener("message",e),"click-to-pay"===this.method||"card"===this.method&&this.clickToPayController&&!0===this.clickToPayConsent?this.clickToPayController.contentWindow.postMessage({type:"submit",channel:d},this.clickToPayUrl):this.controller.contentWindow.postMessage({type:"submit",channel:d,data:{method:this.config.paymentMethodId?"id":"card"}},this.frameUrl)}setDebug(e){localStorage.setItem(l,String(e))}addFont(e){this.font=e.replace(/\s/g,"+")}constructor(e){T(this,"config",void 0),T(this,"controller",void 0),T(this,"frameUrl",void 0),T(this,"apiUrl",void 0),T(this,"parentOrigin",void 0),T(this,"font",void 0),T(this,"cardNumber",void 0),T(this,"securityCode",void 0),T(this,"expiryDate",void 0),T(this,"method","card"),T(this,"clickToPayController",void 0),T(this,"clickToPayUrl",void 0),T(this,"clickToPayOrigin",void 0),T(this,"environmentPath",void 0),T(this,"clickToPayConsent",!1),this.config=k({environment:"production"},e),this.environmentPath="sandbox"===this.config.environment?"sandbox.":"",this.frameUrl=window.SECURE_FIELDS_FRAME_URL||"https://secure-fields.".concat(this.environmentPath).concat(this.config.gr4vyId,".gr4vy.app"),this.parentOrigin=window.location.origin;var t=k({parentOrigin:this.parentOrigin,sessionId:this.config.sessionId,gr4vyId:this.config.gr4vyId,environment:this.config.environment},this.config.paymentMethodId?{paymentMethodId:this.config.paymentMethodId}:{});this.controller=document.createElement("iframe"),this.controller.id="controller",this.controller.src=((e,t)=>"".concat(e,"?").concat(new URLSearchParams(t).toString()))("".concat(this.frameUrl,"/controller.html"),t),this.controller.style.position="absolute",this.controller.style.left="-9999999px",document.body.appendChild(this.controller),this.config.paymentMethodId&&(this.cardNumber=new I,this.expiryDate=new I),window.onload=()=>{h.publish(i.READY,k({version:L.version},this.config))},g("Initialized",S(k({},this.config),{version:L.version,frameUrl:this.frameUrl,parentOrigin:this.parentOrigin})),window.addEventListener("message",(e=>{e.origin===this.frameUrl&&"form-change"===e.data.type&&(h.publish(i.FORM_CHANGE,e.data.data),g("Form change",e.data.data))}))}}return t}()}));
package/lib/input.d.ts CHANGED
@@ -9,7 +9,7 @@ declare class SecureInput {
9
9
  options: Options;
10
10
  addEventListener: EventListener;
11
11
  removeEventListener: EventListener;
12
- constructor(config: Config);
12
+ constructor(config?: Config);
13
13
  _postMessage(message: {
14
14
  type: string;
15
15
  data: Options & {
package/lib/types.d.ts CHANGED
@@ -3,6 +3,7 @@ import type * as CSS from 'csstype';
3
3
  export type Config = {
4
4
  environment?: 'sandbox' | 'production';
5
5
  gr4vyId: string;
6
+ paymentMethodId?: string;
6
7
  sessionId: string;
7
8
  };
8
9
  export type InputConfig = {
@@ -3,3 +3,4 @@ export * from './is';
3
3
  export * from './logger';
4
4
  export * from './strings';
5
5
  export * from './styles';
6
+ export * from './url';
@@ -0,0 +1,8 @@
1
+ declare const parseUrl: (url?: string) => {
2
+ parentOrigin: string;
3
+ type: string;
4
+ font: string;
5
+ };
6
+ declare const buildApiBaseUrl: (gr4vyId: string, environment?: string) => string;
7
+ declare const buildQueryUrl: (url: string, params: Record<string, string>) => string;
8
+ export { buildApiBaseUrl, buildQueryUrl, parseUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gr4vy/secure-fields",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "Gr4vy-hosted secure fields offering advanced theming, PCI compliance, event handling, and more.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index",
@@ -44,14 +44,16 @@
44
44
  "css-loader": "^6.8.1",
45
45
  "csstype": "^3.1.2",
46
46
  "dotenv": "^16.3.1",
47
+ "msw": "^1.3.2",
48
+ "node-fetch": "^2.7.0",
47
49
  "style-loader": "^3.3.3",
48
50
  "ts-patch": "^2.1.0",
49
- "typedoc": "^0.25.1",
50
- "typedoc-plugin-missing-exports": "^2.0.1",
51
+ "typedoc": "^0.25.3",
52
+ "typedoc-plugin-missing-exports": "^2.1.0",
51
53
  "typescript-transform-paths": "^3.4.6"
52
54
  },
53
55
  "publishConfig": {
54
56
  "access": "public"
55
57
  },
56
- "gitHead": "d7d3191e8c52329983e2e0bcf19e24f406b7f5a2"
58
+ "gitHead": "9df00728263ae3bb495c2619521b70bbc004013e"
57
59
  }