@payrails/web-sdk 2.6.1 → 2.7.0-RC

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +2 -2
  2. package/package.json +1 -1
  3. package/payrails.d.ts +121 -83
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- !function(){"use strict";var t;let e;exports.ElementType=void 0,(t=exports.ElementType||(exports.ElementType={})).CARD_NUMBER="CARD_NUMBER",t.CARDHOLDER_NAME="CARDHOLDER_NAME",t.CVV="CVV",t.EXPIRATION_MONTH="EXPIRATION_MONTH",t.EXPIRATION_YEAR="EXPIRATION_YEAR";const n=new Uint8Array(16);function i(){if(!e&&(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!e))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(n)}const o=[];for(let t=0;t<256;++t)o.push((t+256).toString(16).slice(1));var s,a={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function r(t,e,n){if(a.randomUUID&&!e&&!t)return a.randomUUID();const s=(t=t||{}).random||(t.rng||i)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,e){n=n||0;for(let t=0;t<16;++t)e[n+t]=s[t];return e}return function(t,e=0){return(o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]).toLowerCase()}(s)}!function(t){t.GET="GET",t.POST="POST"}(s||(s={}));const l=async({url:t,method:e=s.GET,token:n,body:i})=>{const o={method:e,headers:Object.assign(Object.assign(Object.assign({},h()),c(n)),p())};e===s.POST&&(o.body=JSON.stringify(i||{}));const a=await fetch(t,o),r=await a.json();if([401,403].includes(a.status))throw new d(t,e);if(!a.ok)throw new u(t,e,r);return{ok:a.ok,req:Object.assign({url:t},o),res:r}};class d extends Error{constructor(t,e){super(`[${e}] ${t} unauthorized`)}}class u extends Error{constructor(t,e,n){super(`[${e}] ${t} unsuccessful`),this.res=n}}const c=t=>({authorization:`Bearer ${t}`}),h=()=>({"x-idempotency-key":r()}),p=()=>({"x-client-version":"2.6.1","x-client-type":"web-sdk"});class v{constructor(t,e){this.sdkConfig=t,this.execution=e}async pay(t){const e=(await this.authorize(t)).res.links.execution;return await this.pollForAuthorizationResult(e)}async authorize(t){if(!this.execution.authorizeLink||!this.sdkConfig.amount)throw new Error("SDK was not initialized with workflow execution");return l({url:this.execution.authorizeLink,method:s.POST,token:this.sdkConfig.token,body:{amount:this.sdkConfig.amount,paymentComposition:t,returnInfo:{success:"https://www.bootstrap.payrails.io/success",cancel:"https://www.bootstrap.payrails.io/cancel",error:"https://www.bootstrap.payrails.io/error"}}})}async confirm(t,e={}){const n=await l({url:t,method:s.POST,token:this.sdkConfig.token,body:{data:e}});return this.pollForAuthorizationResult(n.res.links.execution)}async pollForAuthorizationResult(t,e=0){const n=(await this.getExecution(t)).res,i=n.status,o=["authorizePending","authorizeSuccessful","authorizeFailed"],s=i.find((({code:t})=>"authorizeRequested"===t));if(!s&&e<10)return await new Promise((t=>setTimeout(t,300))),this.pollForAuthorizationResult(t,e+1);if(!s)throw new Error("Authorization was not requested");const a=i.find((({code:t,time:e})=>"confirmRequested"===t&&new Date(e)>new Date(s.time))),r=a?a.time:s.time;let l=i.find((({code:t,time:e})=>o.includes(t)&&new Date(e)>new Date(r)));if(!l){const{res:e}=await this.getExecution(t,void 0,r);return l=e.status.find((({code:t,time:e})=>o.includes(t)&&new Date(e)>new Date(r))),{finalState:l,response:e}}return{finalState:l,response:n}}async getExecution(t,e,n){const i=new URLSearchParams;e&&e.length>0&&i.append("waitWhile[status]",`[${e.map((t=>`"${t}"`)).join(",")}]`),n&&i.append("waitWhile[lastStatusTime]",n);const o=`${t}${i.toString()?"?":""}${i.toString()}`;return l({url:o,token:this.sdkConfig.token})}async createApplePaySession(t,e){return l({url:t,method:s.POST,token:this.sdkConfig.token,body:{integrationType:"api",paymentMethodCode:"applePay",amount:this.sdkConfig.amount,meta:{sessionURL:e}}})}}class m{constructor(t){this.loadFunction=t,this.loadScript()}get loader(){return this.loadingPromise||(this.loadingPromise=this.loadScript()),this.loadingPromise}async loadScript(){return this.loadingPromise||(this.loadingPromise=new Promise(((t,e)=>{this.loadFunction().then((n=>{n?t(n):e()}),e)}))),this.loadingPromise}}class y{constructor(t,{id:e="",className:n=""}={}){this.subElements=[];const i=document.createElement(t);e&&(this.id=e,i.setAttribute("id",e)),n&&i.setAttribute("class",n),this.element=i}get parentElement(){return this.element.parentElement}get selector(){if(!this.id)throw new Error("Element id is not set");return`#${this.id}`}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);e.appendChild(this.element),this.subElements.forEach((t=>{if(!this.id)throw new Error("Sub elements can not be rendered, please set id for the element");t.mount(this.selector)}))}unmount(){var t;this.subElements.forEach((t=>t.unmount())),null===(t=this.parentElement)||void 0===t||t.removeChild(this.element)}}class g extends y{constructor(t,e,n){super("div",{id:"payrails-apple-pay-button"}),this.sdkConfig=t,this.execution=e,this.options=n,this.appleButton=null,this.paymentExecutor=new v(t,e),this.loadScript=new m((async()=>{const t=document.createElement("script");return t.src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js",new Promise(((e,n)=>{t.onload=async()=>{var t,n,i;await this.isApplePayAvailable()?(null===(i=null===(n=null===(t=this.options)||void 0===t?void 0:t.events)||void 0===n?void 0:n.onApplePayAvailable)||void 0===i||i.call(n),e(!0)):e(!1)},t.onerror=()=>{n()},document.body.appendChild(t)}))}))}mount(t){super.mount(t),(async()=>{try{await this.loadScript.loader,await this.mountApplePayButton()}catch(t){}})()}unmount(){var t,e;null===(e=null===(t=this.appleButton)||void 0===t?void 0:t.parentElement)||void 0===e||e.removeChild(this.appleButton),super.unmount()}async isApplePayAvailable(){if(!(null===window||void 0===window?void 0:window.ApplePaySession))return!1;return await ApplePaySession.canMakePayments()}async mountApplePayButton(){var t,e;if(null===window||void 0===window?void 0:window.ApplePaySession)try{if(!this.isApplePayAvailable())return;null===(e=null===(t=this.options.events)||void 0===t?void 0:t.onApplePayAvailable)||void 0===e||e.call(t),this.element.innerHTML='<apple-pay-button buttonstyle="black" type="buy" locale="en-GB"></apple-pay-button>';const n=this.element.querySelector("apple-pay-button");null==n||n.setAttribute("style","width: 100%;"),null==n||n.addEventListener("click",(()=>{this.createApplePaySession()}))}catch(t){}}createApplePaySession(){const t=this.execution.applePayConfig,{countryCode:e,supportedNetworks:n,merchantCapabilities:i}=t,{amount:o}=this.sdkConfig;try{const t={countryCode:e,currencyCode:o.currency,merchantCapabilities:i,supportedNetworks:n,total:{label:"",type:"final",amount:o.value}},s=new ApplePaySession(3,t);return s.onvalidatemerchant=async t=>{const{res:e}=await this.paymentExecutor.createApplePaySession(this.execution.createSessionLink,t.validationURL),n=e.data.data;s.completeMerchantValidation(n)},s.onpaymentauthorized=async t=>{var e,n,i,o,a,r,l,d,u,c,h,p;try{const c=await this.onApplePayAuthorized(t.payment.token);if("authorizeSuccessful"===(null===(e=null==c?void 0:c.finalState)||void 0===e?void 0:e.code))(null===(n=this.options.events)||void 0===n?void 0:n.onAuthorizeSuccess)&&this.options.events.onAuthorizeSuccess();else s.completePayment(ApplePaySession.STATUS_FAILURE),(null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o?void 0:o.onAuthorizeFailed)&&(null===(a=this.options)||void 0===a||a.events.onAuthorizeFailed());s.completePayment(ApplePaySession.STATUS_SUCCESS),(null===(l=null===(r=this.options)||void 0===r?void 0:r.events)||void 0===l?void 0:l.onAuthorizeSuccess)&&(null===(u=null===(d=this.options)||void 0===d?void 0:d.events)||void 0===u||u.onAuthorizeSuccess(c))}catch(t){s.completePayment(ApplePaySession.STATUS_FAILURE),(null===(h=null===(c=this.options)||void 0===c?void 0:c.events)||void 0===h?void 0:h.onAuthorizeFailed)&&(null===(p=this.options)||void 0===p||p.events.onAuthorizeFailed(t))}},s.begin(),s}catch(t){return null}}async onApplePayAuthorized(t){const e={paymentData:t.paymentData,transactionIdentifier:t.transactionIdentifier,paymentNetwork:t.paymentMethod.network,paymentInstrumentName:t.paymentMethod.displayName},n=[{paymentMethodCode:"applePay",integrationType:"api",paymentInstrumentData:{paymentToken:JSON.stringify(e)},amount:this.sdkConfig.amount}];return await this.paymentExecutor.pay(n)}}class f extends y{constructor(t){super("span",{id:t.id,className:"payrails-store-instrument"}),this.options=t,this.createHTML(),this.applyStyles(),this.addListeners()}get isChecked(){var t;return!!(null===(t=this.element.querySelector("input"))||void 0===t?void 0:t.checked)}createHTML(){var t;const e=(null===(t=this.options)||void 0===t?void 0:t.label)||"Save instrument for future payments",n=`${this.id}-checkbox`;this.element.innerHTML=`<label for="${n}"><input type="checkbox" id="${n}" name="${n}" class="payrails-store-instrument-checkbox">${e}</label>`}applyStyles(){var t;Object.keys((null===(t=this.options)||void 0===t?void 0:t.styles)||{}).forEach((t=>{var e,n;this.element.style[t]=null===(n=null===(e=this.options)||void 0===e?void 0:e.styles)||void 0===n?void 0:n[t]}))}addListeners(){this.element.addEventListener("change",(t=>{var e,n,i,o;(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onSaveInstrumentCheckboxChanged)&&(null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o||o.onSaveInstrumentCheckboxChanged({checked:this.isChecked})),t.stopPropagation(),t.stopImmediatePropagation()}))}}const{CARD_NUMBER:b,CVV:C,CARDHOLDER_NAME:w,EXPIRATION_MONTH:A,EXPIRATION_YEAR:k}=exports.ElementType,x={base:{border:"none",padding:"10px 16px",color:"#1d1d1d",backgroundColor:"#fff"},invalid:{backgroundColor:"#f9e1e1",borderColor:"#f25226",border:"1px solid"}},P=[{type:w,placeholder:"Card holder",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{border:"1px solid #eae8ee",padding:"10px 16px",borderTopLeftRadius:"4px",borderTopRightRadius:"4px"})})},{type:b,placeholder:"1234 1234 1234 1234",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{border:"1px solid #eae8ee",padding:"10px 16px",borderTopLeftRadius:"4px",borderTopRightRadius:"4px",textIndent:"0"}),cardIcon:{position:"absolute",right:"8px",height:"24px",bottom:"calc(50% - 12px)"}})},{type:A,placeholder:"MM",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{borderBottom:"1px solid #eae8ee",borderLeft:"1px solid #eae8ee",borderRight:"1px solid #eae8ee",borderBottomLeftRadius:"4px"})})},{type:k,placeholder:"YY",format:"YY",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{borderBottom:"1px solid #eae8ee",borderRight:"1px solid #eae8ee"})})},{type:C,placeholder:"CVC",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{borderBottom:"1px solid #eae8ee",borderRight:"1px solid #eae8ee",borderBottomRightRadius:"4px"})})}];class E extends y{constructor(t,e){var n,i,o,s,a;super("div",{id:"payrails-card-form"}),this.collectContainer=t,this.options=e,this.storeCardCheckbox=null,this.formFields=[],P.forEach((({type:t,styles:n,format:i,placeholder:o})=>{var s,a,r,l,d,u,c;if(!(null===(s=this.options)||void 0===s?void 0:s.showCardHolderName)&&t===exports.ElementType.CARDHOLDER_NAME)return;const h=new S(this.collectContainer,{type:t,label:null===(r=null===(a=null==e?void 0:e.translations)||void 0===a?void 0:a.labels)||void 0===r?void 0:r[t],placeholder:(null===(d=null===(l=null==e?void 0:e.translations)||void 0===l?void 0:l.placeholders)||void 0===d?void 0:d[t])||o,labelStyles:this.prepareLabelStyles(t),inputStyles:this.prepareInputStyles(n,t),format:i,events:{onFocus:null===(c=null===(u=this.options)||void 0===u?void 0:u.events)||void 0===c?void 0:c.onFocus,onChange:this.onChange.bind(this)}});this.formFields.push(h)})),this.subElements.push(this.collectContainer),(null===(n=this.options)||void 0===n?void 0:n.showStoreInstrumentCheckbox)&&(this.storeCardCheckbox=new f({id:"payrails-store-card",label:null===(o=null===(i=this.options.translations)||void 0===i?void 0:i.labels)||void 0===o?void 0:o.saveCreditCard,styles:null===(s=this.options.styles)||void 0===s?void 0:s.storeCardCheckbox,events:{onSaveInstrumentCheckboxChanged:null===(a=this.options.events)||void 0===a?void 0:a.onSaveInstrumentCheckboxChanged}}),this.subElements.push(this.storeCardCheckbox))}show(){this.element.style.display="flex"}hide(){this.element.style.display="none"}prepareLabelStyles(t){return["base"].reduce(((e,n)=>{var i,o,s,a,r,l,d,u;return e[n]=Object.assign(Object.assign(Object.assign({},null===(o=null===(i=this.options)||void 0===i?void 0:i.styles)||void 0===o?void 0:o.base),null===(r=null===(a=null===(s=this.options)||void 0===s?void 0:s.styles)||void 0===a?void 0:a.labels)||void 0===r?void 0:r.all),null===(u=null===(d=null===(l=this.options)||void 0===l?void 0:l.styles)||void 0===d?void 0:d.labels)||void 0===u?void 0:u[t]),e}),{})}prepareInputStyles(t,e){var n;let i=JSON.parse(JSON.stringify(t));return(null===(n=this.options)||void 0===n?void 0:n.showCardHolderName)&&e===exports.ElementType.CARD_NUMBER&&(this.element.setAttribute("class","with-card-holder"),i=Object.assign(Object.assign({},t),{base:Object.assign(Object.assign({},x.base),{border:"1px solid #eae8ee",borderTop:"none",padding:"10px 16px",textIndent:"0"})})),["base","complete","empty","focus","invalid","cardIcon","copyIcon"].forEach((t=>{var n,o,s,a,r,l,d,u;i[t]=Object.assign(Object.assign(Object.assign({},i[t]),null===(a=null===(s=null===(o=null===(n=this.options)||void 0===n?void 0:n.styles)||void 0===o?void 0:o.inputFields)||void 0===s?void 0:s.all)||void 0===a?void 0:a[t]),null===(u=null===(d=null===(l=null===(r=this.options)||void 0===r?void 0:r.styles)||void 0===l?void 0:l.inputFields)||void 0===d?void 0:d[e])||void 0===u?void 0:u[t])})),i}get isValid(){return this.formFields.reduce(((t,e)=>t&&e.isValid),!0)}get cardNetwork(){var t,e;return null!==(e=null===(t=this.formFields.find((t=>Boolean(t.cardNetwork))))||void 0===t?void 0:t.cardNetwork)&&void 0!==e?e:""}onChange(){var t,e,n,i;(null===(e=null===(t=this.options)||void 0===t?void 0:t.events)||void 0===e?void 0:e.onChange)&&(null===(i=null===(n=this.options)||void 0===n?void 0:n.events)||void 0===i||i.onChange({isValid:this.isValid,cardNetwork:this.cardNetwork}))}async collectValues(){var t,e,n;return{tokenizedCardData:await this.collectContainer.collect(),storeInstrument:(null===(t=this.storeCardCheckbox)||void 0===t?void 0:t.isChecked)||(null===(e=this.options)||void 0===e?void 0:e.alwaysStoreInstrument),enrollInstrumentToNetworkOffers:Boolean(null===(n=this.options)||void 0===n?void 0:n.enrollInstrumentToNetworkOffers)}}}class S{constructor(t,e){this.isValid=!1,this.cardNetwork="";const{events:n}=e,i=t.createCollectElement(e);(null==n?void 0:n.onFocus)&&i.on("FOCUS",n.onFocus),i.on("CHANGE",(t=>{const{isEmpty:e,isValid:i,network:o}=t;this.isValid=!e&&i,this.cardNetwork=null!=o?o:"",(null==n?void 0:n.onChange)&&n.onChange(this)}))}}class _ extends y{constructor(t,e){super("div",{id:"payrails-card-list"}),this.workflowExecution=t,this.listItems=[],this.workflowExecution.savedCreditCards.forEach((t=>{const n=new O((()=>{(null==e?void 0:e.onCardChange)&&e.onCardChange(t)}),t);this.listItems.push(n),this.subElements.push(n)}))}reset(){this.element.querySelectorAll("input").forEach((t=>t.checked=!1))}}class O extends y{constructor(t,e){super("div",{className:"payrails-card-list-item",id:`payrails-card-list-item-${e.id}`});const{id:n}=e,i=this.createCardLabel(e),o=document.createElement("label");o.setAttribute("for",n),o.addEventListener("click",t);const s=document.createElement("input");s.setAttribute("type","radio"),s.setAttribute("name","payment-option"),s.setAttribute("id",n),s.setAttribute("value",n),o.appendChild(s);const a=document.createElement("span");a.innerText=i,o.appendChild(a),this.element.appendChild(o)}createCardLabel({data:{suffix:t}}){return`****${t}`}}var I,B;!function(t){t.CARD="card",t.GOOGLE_PAY="googlePay",t.PAYPAL="payPal",t.APPLE_PAY="applePay"}(I||(I={})),function(t){t.ENABLED="enabled",t.CREATED="created"}(B||(B={}));class T{constructor(t){this.executionResponse=t}get lookup(){return this.executionResponse.initialResults.find((({body:{name:t}})=>"lookup"===t))}get holderReference(){return this.executionResponse.holderReference}get savedCreditCards(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===I.CARD));return(null==t?void 0:t.paymentInstruments)||[]}get savedPaypalAccounts(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===I.PAYPAL));return(null==t?void 0:t.paymentInstruments)||[]}get paypalConfig(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===I.PAYPAL));if(!t)throw new Error("trying to initialize paypal without config");return t.config}get googlePayConfig(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===I.GOOGLE_PAY));if(!t)throw new Error("trying to initialize google pay without config");return t?[t.config]:[]}get applePayConfig(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===I.APPLE_PAY));if(!t)throw new Error("apple pay config not found");return t.config.parameters}get url(){return this.response.links.self}get response(){return this.executionResponse}get meta(){return this.executionResponse.meta}get availablePaymentMethods(){var t;return(null===(t=this.lookup)||void 0===t?void 0:t.body.data.paymentCompositionOptions)||[]}get authorizeLink(){var t;return null===(t=this.lookup)||void 0===t?void 0:t.body.links.authorize.href}get createSessionLink(){return this.response.links.startPaymentSession.href}}class L extends y{constructor(t,e,n){var i;super("button",{id:"payrails-card-payment-button"}),this.sdkConfig=t,this.execution=e,this.options=n,this.selectedCard=null,this.element.innerText=(null===(i=null==n?void 0:n.translations)||void 0===i?void 0:i.label)||"Pay",this.element.addEventListener("click",this.onPay.bind(this)),this.element.addEventListener("mouseenter",(()=>{var t;this.element.classList.contains("disabled")||(this.element.classList.add("hover"),this.setStyles((null===(t=this.options.styles)||void 0===t?void 0:t.hover)||{}))})),this.element.addEventListener("mouseleave",(()=>{var t;this.element.classList.contains("disabled")||(this.element.classList.remove("hover"),this.removeStyles((null===(t=this.options.styles)||void 0===t?void 0:t.hover)||{}))})),this.paymentExecutor=new v(this.sdkConfig,this.execution)}setDisabled(t){var e,n,i;this.element.disabled=t,t?(this.element.classList.add("disabled"),(null===(e=this.options.styles)||void 0===e?void 0:e.disabled)&&this.setStyles(this.options.styles.disabled)):(this.element.classList.remove("disabled"),this.removeStyles((null===(n=this.options.styles)||void 0===n?void 0:n.disabled)||{}),(null===(i=this.options.styles)||void 0===i?void 0:i.base)&&this.setStyles(this.options.styles.base))}setSavedCreditCard(t){this.selectedCard=t,this.setDisabled(!1)}setStyles(t){var e;const n=Object.assign(Object.assign({},null===(e=this.options.styles)||void 0===e?void 0:e.base),t);Object.keys(n).forEach((t=>{this.element.style[t]=n[t]}))}removeStyles(t){var e;const n=Object.keys((null===(e=this.options.styles)||void 0===e?void 0:e.base)||{});Object.keys(t).forEach((t=>{var e,i;n.includes(t)?this.element.style[t]=null===(i=null===(e=this.options.styles)||void 0===e?void 0:e.base)||void 0===i?void 0:i[t]:this.element.style[t]=""}))}setLabel(t){this.element.innerText=t}setCardForm(t){this.cardForm=t}triggerLoading(t){var e,n,i,o;const s=this.element.offsetWidth;this.element.style.minWidth=`${s}px`,t?(this.element.innerHTML='<div class="dot-flashing"></div>',this.element.classList.add("loading"),(null===(e=this.options.styles)||void 0===e?void 0:e.loading)&&this.setStyles(this.options.styles.loading)):(this.element.innerText=(null===(i=null===(n=this.options)||void 0===n?void 0:n.translations)||void 0===i?void 0:i.label)||"Pay",this.element.classList.remove("loading"),this.removeStyles((null===(o=this.options.styles)||void 0===o?void 0:o.loading)||{}))}onAuthorizationFailed(){var t,e;this.setDisabled(!1),this.triggerLoading(!1),(null===(t=this.options.events)||void 0===t?void 0:t.onAuthorizeFailed)&&(null===(e=this.options.events)||void 0===e||e.onAuthorizeFailed())}async onPay(){var t,e,n,i,o,s,a;if(this.setDisabled(!0),this.triggerLoading(!0),null===(t=this.options.events)||void 0===t?void 0:t.onPaymentButtonClicked){if(!1===await(null===(e=this.options.events)||void 0===e?void 0:e.onPaymentButtonClicked()))return void this.onAuthorizationFailed()}try{const t=[{paymentMethodCode:I.CARD,integrationType:"api",amount:this.sdkConfig.amount,storeInstrument:!1}];if(null===(n=this.selectedCard)||void 0===n?void 0:n.id)t[0].paymentInstrumentId=null===(i=this.selectedCard)||void 0===i?void 0:i.id;else{const{tokenizedCardData:e,storeInstrument:n,enrollInstrumentToNetworkOffers:i}=await this.collectCardFormValues();t[0].paymentInstrumentData={vaultToken:null==e?void 0:e.instrumentId,card:{numberToken:null==e?void 0:e.card_number,securityCodeToken:null==e?void 0:e.security_code}},t[0].storeInstrument=n,t[0].enrollInstrumentToNetworkOffers=i}const e=await this.paymentExecutor.pay(t);this.handleAuthorizationResult(e)}catch(t){(t instanceof d||[401,403].includes(null===(o=null==t?void 0:t.error)||void 0===o?void 0:o.code))&&(null===(a=null===(s=this.options.events)||void 0===s?void 0:s.onPaymentSessionExpired)||void 0===a||a.call(s)),this.onAuthorizationFailed()}}handleAuthorizationResult(t){var e,n,i;switch(null===(e=null==t?void 0:t.finalState)||void 0===e?void 0:e.code){case"authorizeSuccessful":this.triggerLoading(!1),(null===(n=this.options.events)||void 0===n?void 0:n.onAuthorizeSuccess)&&this.options.events.onAuthorizeSuccess();break;case"authorizePending":"3ds"===(null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.actionRequired)&&this.handle3ds(t);break;default:this.onAuthorizationFailed()}}handle3ds(t){var e,n;const i=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.links["3ds"];if(i){const t=[[250,400],[390,400],[500,600],[600,400]],e=screen.width,o=t.reduce(((t,n)=>e>n[0]?n:t),[250,400]),s=document.createElement("iframe");s.setAttribute("id","payrails-3ds-frame"),s.setAttribute("src",i),s.setAttribute("width",o[0].toString()),s.setAttribute("height",o[1].toString());const a=document.createElement("div");a.setAttribute("id","payrails-3ds-challenge"),a.appendChild(s);const r=document.createElement("div");r.addEventListener("click",(async()=>{r.remove()})),r.setAttribute("id","payrails-3ds-popup-background"),r.appendChild(a);const l=async t=>{var e,n,i;if(t.data&&'{"type":"3DS-challenge-completed"}'===t.data){window.removeEventListener("message",l),r.remove();if(!(await this.paymentExecutor.getExecution(this.execution.url)).res.status.find((({code:t})=>"authorizeSuccessful"===t))&&(null===(e=this.options.events)||void 0===e?void 0:e.onAuthorizeFailed))return void this.onAuthorizationFailed();if(null===(n=this.options.events)||void 0===n?void 0:n.onAuthorizeSuccess)return void(null===(i=this.options.events)||void 0===i||i.onAuthorizeSuccess())}};null===(n=document.querySelector("body"))||void 0===n||n.appendChild(r),window.addEventListener("message",l),a.style.width=`${o[0]+4}px`,a.style.height=`${o[1]+4}px`}}async collectCardFormValues(){if(!this.cardForm)throw new Error("Trying to collect values from non-existent card form");return await this.cardForm.collectValues()}}class z extends y{constructor(t="Authorization failed, please try again."){super("div",{id:"authorization-failed-message"}),this.element.innerText=t,this.element.innerHTML=`\n <div>\n <svg class="checkmark-cross" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">\n <circle class="checkmark-cross_circle" cx="26" cy="26" r="25" fill="none"/>\n <path class="checkmark-cross_check" fill="none" d="M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8"/>\n </svg>\n </div>\n <div>${t}</div>`,this.element.addEventListener("click",(t=>{t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation(),this.unmount()}))}}class F extends y{constructor(t){var e;super("div",{id:"payrails-authorization-success-msg"}),this.element.innerHTML=`\n <div class="checkmark-wrapper">\n <svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">\n <circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>\n <path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>\n </svg>\n </div>\n <div id="payrails-authorization-success">${(null===(e=null==t?void 0:t.translations)||void 0===e?void 0:e.label)||"Payment successful"}</div`}}class j extends y{constructor(t,e,n){super("div",{id:t,className:"payrails-dropin-item"}),this.events=n,this.isActive=!1;const i=`payrails-dropin-item-${t}`,o=document.createElement("label");o.setAttribute("for",i);const s=document.createElement("input");s.setAttribute("type","radio"),s.setAttribute("name","payment-option"),s.setAttribute("id",i),s.setAttribute("value",i),this.input=s,o.appendChild(s),this.label=o;const a=document.createElement("span");o.appendChild(a),a.innerText=e,this.element.appendChild(o)}get identifier(){return`payrails-dropin-item-${this.id}`}deactivate(){var t,e;this.isActive&&(this.isActive=!1,this.label.style.marginBottom="0",null===(t=this.component)||void 0===t||t.unmount(),(null===(e=this.events)||void 0===e?void 0:e.onDeactivate)&&this.events.onDeactivate())}activate(){var t,e;this.isActive||(null===(t=this.component)||void 0===t||t.mount(this.selector),this.label.style.marginBottom="8px",this.isActive=!0,(null===(e=this.events)||void 0===e?void 0:e.onActivate)&&this.events.onActivate())}}class R extends j{constructor(){super(...arguments),this.buttonShown=!1}activate(){if(!this.buttonShown)return super.activate(),void(this.buttonShown=!0);this.label.style.marginBottom="8px",this.isActive=!0,this.element.querySelector(this.component.selector).style.display="block"}deactivate(){this.isActive&&(this.isActive=!1,this.label.style.marginBottom="0",this.element.querySelector(this.component.selector).style.display="none")}mountAfterAvailable(){super.mount(`#${this.loadElementId}`)}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);const n=document.createElement("div");n.setAttribute("id",this.loadElementId),n.setAttribute("style","width: 100%;"),e.appendChild(n)}unmount(){var t;super.unmount(),null===(t=document.querySelector(`#${this.loadElementId}`))||void 0===t||t.remove()}}class N extends R{constructor(t,e,n){var i;super("apple-pay-dropin",(null===(i=n.translations)||void 0===i?void 0:i.label)||"Apple Pay"),this.loadElementId="apple-pay-dropin-load-element",this.component=new g(t,e,Object.assign(Object.assign({},n),{events:{onApplePayAvailable:()=>{this.mountAfterAvailable()}}}))}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);const n=document.createElement("div");n.setAttribute("id",this.loadElementId),n.setAttribute("style","width: 100%;"),e.appendChild(n)}}class D extends j{constructor(t,e){super("payrails-credit-card-wrapper","Card"),this.cardForm=t,this.paymentButton=e,this.cardFormShown=!1,this.component=new M(t,e)}activate(){var t,e;this.label.style.marginBottom="8px",this.cardFormShown||(this.cardFormShown=!0,null===(t=this.component)||void 0===t||t.mount(this.selector)),this.isActive||(this.paymentButton.selectedCard=null,this.paymentButton.mount(this.selector),this.paymentButton.setDisabled(!this.cardForm.isValid),this.paymentButton.mount("#payrails-card-form"),this.input.checked=!0,this.cardForm.show(),this.isActive=!0,(null===(e=this.events)||void 0===e?void 0:e.onActivate)&&this.events.onActivate())}deactivate(){var t;this.isActive&&(this.label.style.marginBottom="0",this.paymentButton.unmount(),this.cardForm.hide(),this.isActive=!1,(null===(t=this.events)||void 0===t?void 0:t.onDeactivate)&&this.events.onDeactivate())}}class M extends y{constructor(t,e){super("div",{id:"payrails-form-container"}),this.subElements.push(t,e)}}const $={apiVersion:2,apiVersionMinor:0};class U extends y{constructor(t,e,n){super("div",{id:"payrails-google-pay-button"}),this.sdkConfig=t,this.execution=e,this.options=n,this.googleButton=null,this.paymentExecutor=new v(t,e),this.loadScript=new m((async()=>{const t=document.createElement("script");return t.src="https://pay.google.com/gp/p/js/pay.js",new Promise(((e,n)=>{t.onload=()=>{const t=new google.payments.api.PaymentsClient({environment:this.options.environment||"TEST"}),i=Object.assign(Object.assign({},$),{allowedPaymentMethods:this.execution.googlePayConfig});t.isReadyToPay(i).then((i=>{var o,s,a;i?(null===(a=null===(s=null===(o=this.options)||void 0===o?void 0:o.events)||void 0===s?void 0:s.onGooglePayAvailable)||void 0===a||a.call(s),e(t)):n()}),n)},t.onerror=()=>{n()},document.body.appendChild(t)}))}))}async sdkLoaded(t){var e,n,i,o,s,a,r,l;try{const d=(null===(n=null===(e=this.options)||void 0===e?void 0:e.styles)||void 0===n?void 0:n.buttonColor)||"black",u=(null===(o=null===(i=this.options)||void 0===i?void 0:i.styles)||void 0===o?void 0:o.buttonType)||"long",c=(null===(a=null===(s=this.options)||void 0===s?void 0:s.styles)||void 0===a?void 0:a.buttonSizeMode)||"fill",h=(null===(l=null===(r=this.options)||void 0===r?void 0:r.styles)||void 0===l?void 0:l.buttonLocale)||void 0;return this.googleButton=t.createButton({buttonColor:d,buttonType:u,buttonSizeMode:c,buttonLocale:h,onClick:async()=>{var t,e,n;if(null===(e=null===(t=this.options)||void 0===t?void 0:t.events)||void 0===e?void 0:e.onPaymentButtonClicked){if(!await(null===(n=this.options)||void 0===n?void 0:n.events.onPaymentButtonClicked()))return}await this.onPaymentButtonClicked()},allowedPaymentMethods:this.execution.googlePayConfig}),this.element.appendChild(this.googleButton),this.googleButton}catch(t){throw console.error("Google pay can not be initialized",t),new Error(t.message)}}async onLoadPaymentData(t){var e,n,i,o;const s=[{paymentMethodCode:"googlePay",integrationType:"api",paymentInstrumentData:{paymentToken:t.paymentMethodData.tokenizationData.token},amount:this.sdkConfig.amount}],a=await this.paymentExecutor.pay(s);(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onAuthorizeSuccess)&&(null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o||o.onAuthorizeSuccess(a))}async onPaymentButtonClicked(){var t,e,n,i,o;const s=Object.assign({},$);s.allowedPaymentMethods=this.execution.googlePayConfig,s.transactionInfo={totalPriceStatus:"FINAL",totalPrice:null===(t=this.sdkConfig.amount)||void 0===t?void 0:t.value,currencyCode:null===(e=this.sdkConfig.amount)||void 0===e?void 0:e.currency,countryCode:null===(o=null===(i=null===(n=this.execution.meta)||void 0===n?void 0:n.customer)||void 0===i?void 0:i.country)||void 0===o?void 0:o.code};(await this.loadScript.loader).loadPaymentData(s).then((t=>{this.onLoadPaymentData(t)})).catch((t=>{var e,n,i;(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onAuthorizeFailed)&&(null===(i=this.options)||void 0===i||i.events.onAuthorizeFailed(t))}))}mount(t){super.mount(t),(async()=>{try{const t=await this.loadScript.loader,e=await this.sdkLoaded(t);this.element.appendChild(e)}catch(t){}})()}unmount(){var t;this.googleButton&&(null===(t=this.googleButton.parentElement)||void 0===t||t.removeChild(this.googleButton)),super.unmount()}}class V extends R{constructor(t,e,n){var i;super("google-pay-dropin",(null===(i=n.translations)||void 0===i?void 0:i.label)||"Google Pay"),this.loadElementId="google-pay-dropin-load-element",this.component=new U(t,e,Object.assign(Object.assign({},n),{events:Object.assign(Object.assign({},n.events),{onGooglePayAvailable:()=>{this.mountAfterAvailable()}})}))}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);const n=document.createElement("div");n.setAttribute("id",this.loadElementId),n.setAttribute("style","width: 100%;"),e.appendChild(n)}}
1
+ !function(){"use strict";var t;let e;exports.ElementType=void 0,(t=exports.ElementType||(exports.ElementType={})).CARD_NUMBER="CARD_NUMBER",t.CARDHOLDER_NAME="CARDHOLDER_NAME",t.CVV="CVV",t.EXPIRATION_MONTH="EXPIRATION_MONTH",t.EXPIRATION_YEAR="EXPIRATION_YEAR";const n=new Uint8Array(16);function i(){if(!e&&(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!e))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(n)}const o=[];for(let t=0;t<256;++t)o.push((t+256).toString(16).slice(1));var s,a={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function r(t,e,n){if(a.randomUUID&&!e&&!t)return a.randomUUID();const s=(t=t||{}).random||(t.rng||i)();if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,e){n=n||0;for(let t=0;t<16;++t)e[n+t]=s[t];return e}return function(t,e=0){return(o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]).toLowerCase()}(s)}!function(t){t.GET="GET",t.POST="POST"}(s||(s={}));const l=async({url:t,method:e=s.GET,token:n,body:i})=>{const o={method:e,headers:Object.assign(Object.assign(Object.assign({},h()),c(n)),v())};e===s.POST&&(o.body=JSON.stringify(i||{}));const a=await fetch(t,o),r=await a.json();if([401,403].includes(a.status))throw new d(t,e);if(!a.ok)throw new u(t,e,r);return{ok:a.ok,req:Object.assign({url:t},o),res:r}};class d extends Error{constructor(t,e){super(`[${e}] ${t} unauthorized`)}}class u extends Error{constructor(t,e,n){super(`[${e}] ${t} unsuccessful`),this.res=n}}const c=t=>({authorization:`Bearer ${t}`}),h=()=>({"x-idempotency-key":r()}),v=()=>({"x-client-version":"2.7.0-RC","x-client-type":"web-sdk"});class p{constructor(t,e,n){this.sdkConfig=t,this.execution=e,this.returnLinks=n}async pay(t){const e=(await this.authorize(t)).res.links.execution;return await this.pollForAuthorizationResult(e)}async authorize(t){if(!this.execution.authorizeLink||!this.sdkConfig.amount)throw new Error("SDK was not initialized with workflow execution");const{success:e="https://payrails.io/success",error:n="https://payrails.io/error",cancel:i="https://payrails.io/cancel"}=this.returnLinks||{};return l({url:this.execution.authorizeLink,method:s.POST,token:this.sdkConfig.token,body:{amount:this.sdkConfig.amount,paymentComposition:t,returnInfo:{success:e,cancel:i,error:n}}})}async confirm(t,e={}){const n=await l({url:t,method:s.POST,token:this.sdkConfig.token,body:{data:e}});return this.pollForAuthorizationResult(n.res.links.execution)}async pollForAuthorizationResult(t,e=0){const n=(await this.getExecution(t)).res,i=n.status,o=["authorizePending","authorizeSuccessful","authorizeFailed"],s=i.find((({code:t})=>"authorizeRequested"===t));if(!s&&e<10)return await new Promise((t=>setTimeout(t,300))),this.pollForAuthorizationResult(t,e+1);if(!s)throw new Error("Authorization was not requested");const a=i.find((({code:t,time:e})=>"confirmRequested"===t&&new Date(e)>new Date(s.time))),r=a?a.time:s.time;let l=i.find((({code:t,time:e})=>o.includes(t)&&new Date(e)>new Date(r)));if(!l){const{res:e}=await this.getExecution(t,void 0,r);return l=e.status.find((({code:t,time:e})=>o.includes(t)&&new Date(e)>new Date(r))),{finalState:l,response:e}}return{finalState:l,response:n}}async getExecution(t,e,n){const i=new URLSearchParams;e&&e.length>0&&i.append("waitWhile[status]",`[${e.map((t=>`"${t}"`)).join(",")}]`),n&&i.append("waitWhile[lastStatusTime]",n);const o=`${t}${i.toString()?"?":""}${i.toString()}`;return l({url:o,token:this.sdkConfig.token})}async createApplePaySession(t,e){return l({url:t,method:s.POST,token:this.sdkConfig.token,body:{integrationType:"api",paymentMethodCode:"applePay",amount:this.sdkConfig.amount,meta:{sessionURL:e}}})}}class m{constructor(t){this.loadFunction=t,this.loadScript()}get loader(){return this.loadingPromise||(this.loadingPromise=this.loadScript()),this.loadingPromise}async loadScript(){return this.loadingPromise||(this.loadingPromise=new Promise(((t,e)=>{this.loadFunction().then((e=>{e&&t(e)}),(()=>{e()})).catch((()=>{}))}))),this.loadingPromise}}class y{constructor(t,{id:e="",className:n=""}={}){this.subElements=[];const i=document.createElement(t);e&&(this.id=e,i.setAttribute("id",e)),n&&i.setAttribute("class",n),this.element=i}get parentElement(){return this.element.parentElement}get selector(){if(!this.id)throw new Error("Element id is not set");return`#${this.id}`}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);e.appendChild(this.element),this.subElements.forEach((t=>{if(!this.id)throw new Error("Sub elements can not be rendered, please set id for the element");t.mount(this.selector)}))}unmount(){var t;this.subElements.forEach((t=>t.unmount())),null===(t=this.parentElement)||void 0===t||t.removeChild(this.element)}}class g extends y{constructor(t){super("span",{id:t.id,className:"payrails-store-instrument"}),this.options=t,this.createHTML(),this.applyStyles(),this.addListeners()}get isChecked(){var t;return!!(null===(t=this.element.querySelector("input"))||void 0===t?void 0:t.checked)}createHTML(){var t,e,n,i,o,s,a,r,l;const d=(null===(n=null===(e=null===(t=this.options)||void 0===t?void 0:t.translations)||void 0===e?void 0:e.labels)||void 0===n?void 0:n.saveInstrument)||(null===(s=null===(o=null===(i=this.options)||void 0===i?void 0:i.translations)||void 0===o?void 0:o.labels)||void 0===s?void 0:s.storeInstrument)||"Save instrument for future payments",u=`${this.id}-checkbox`;(null===(l=null===(r=null===(a=this.options)||void 0===a?void 0:a.translations)||void 0===r?void 0:r.labels)||void 0===l?void 0:l.saveInstrument)&&console.warn("The saveInstrument label is deprecated, please use storeInstrument instead"),this.element.innerHTML=`<label for="${u}"><input type="checkbox" id="${u}" name="${u}" class="payrails-store-instrument-checkbox">${d}</label>`}applyStyles(){var t,e;Object.keys((null===(e=null===(t=this.options)||void 0===t?void 0:t.styles)||void 0===e?void 0:e.storeInstrumentCheckbox)||{}).forEach((t=>{var e,n,i;this.element.style[t]=null===(i=null===(n=null===(e=this.options)||void 0===e?void 0:e.styles)||void 0===n?void 0:n.storeInstrumentCheckbox)||void 0===i?void 0:i[t]}))}addListeners(){this.element.addEventListener("change",(t=>{var e,n,i,o;(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onSaveInstrumentCheckboxChanged)&&(null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o||o.onSaveInstrumentCheckboxChanged({checked:this.isChecked})),t.stopPropagation(),t.stopImmediatePropagation()}))}}class b extends y{constructor(t,e){var n,i;super(t,e),this.options=e,this.storeInstrumentCheckbox=null,(null===(n=this.options)||void 0===n?void 0:n.showStoreInstrumentCheckbox)&&(this.storeInstrumentCheckbox=new g(Object.assign(Object.assign({},e),{id:`${null===(i=this.options)||void 0===i?void 0:i.id}-store-instrument-checkbox`,events:{onSaveInstrumentCheckboxChanged:async t=>{var n,i;null===(i=null===(n=null==e?void 0:e.events)||void 0===n?void 0:n.onSaveInstrumentCheckboxChanged)||void 0===i||i.call(n,t)}}})),this.subElements.push(this.storeInstrumentCheckbox))}get shouldStoreInstrument(){var t,e;return(null===(t=this.storeInstrumentCheckbox)||void 0===t?void 0:t.isChecked)||(null===(e=this.options)||void 0===e?void 0:e.alwaysStoreInstrument)||!1}}class f extends b{constructor(t,e,n){super("div",Object.assign(Object.assign({},n),{id:"payrails-apple-pay-button"})),this.sdkConfig=t,this.execution=e,this.options=n,this.appleButton=null,this.paymentExecutor=new p(t,e),this.loadScript=new m((async()=>{const t=document.createElement("script");return t.src="https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js",new Promise(((e,n)=>{t.onload=async()=>{var t,n,i;await this.isApplePayAvailable()?(null===(i=null===(n=null===(t=this.options)||void 0===t?void 0:t.events)||void 0===n?void 0:n.onApplePayAvailable)||void 0===i||i.call(n),e(!0)):e(!1)},t.onerror=()=>{n()},document.body.appendChild(t)}))}))}mount(t){super.mount(t),(async()=>{try{await this.loadScript.loader,await this.mountApplePayButton()}catch(t){}})()}unmount(){var t,e;null===(e=null===(t=this.appleButton)||void 0===t?void 0:t.parentElement)||void 0===e||e.removeChild(this.appleButton),super.unmount()}async isApplePayAvailable(){if(!(null===window||void 0===window?void 0:window.ApplePaySession))return!1;return await ApplePaySession.canMakePayments()}async mountApplePayButton(){var t,e,n;if(null===window||void 0===window?void 0:window.ApplePaySession)try{if(!this.isApplePayAvailable())return;null===(t=this.storeInstrumentCheckbox)||void 0===t||t.mount(this.selector),null===(n=null===(e=this.options.events)||void 0===e?void 0:e.onApplePayAvailable)||void 0===n||n.call(e),this.element.innerHTML='<apple-pay-button buttonstyle="black" type="buy" locale="en-GB"></apple-pay-button>';const i=this.element.querySelector("apple-pay-button");null==i||i.setAttribute("style","width: 100%;"),null==i||i.addEventListener("click",(()=>{this.createApplePaySession()}))}catch(t){}}createApplePaySession(){const t=this.execution.applePayConfig,{countryCode:e,supportedNetworks:n,merchantCapabilities:i}=t,{amount:o}=this.sdkConfig;try{const t={countryCode:e,currencyCode:o.currency,merchantCapabilities:i,supportedNetworks:n,total:{label:"",type:"final",amount:o.value}},s=new ApplePaySession(3,t);return s.onvalidatemerchant=async t=>{const{res:e}=await this.paymentExecutor.createApplePaySession(this.execution.createSessionLink,t.validationURL),n=e.data.data;s.completeMerchantValidation(n)},s.onpaymentauthorized=async t=>{var e,n,i,o,a,r,l,d,u,c,h,v;try{const c=await this.onApplePayAuthorized(t.payment.token);if("authorizeSuccessful"===(null===(e=null==c?void 0:c.finalState)||void 0===e?void 0:e.code))(null===(n=this.options.events)||void 0===n?void 0:n.onAuthorizeSuccess)&&this.options.events.onAuthorizeSuccess();else s.completePayment(ApplePaySession.STATUS_FAILURE),(null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o?void 0:o.onAuthorizeFailed)&&(null===(a=this.options)||void 0===a||a.events.onAuthorizeFailed());s.completePayment(ApplePaySession.STATUS_SUCCESS),(null===(l=null===(r=this.options)||void 0===r?void 0:r.events)||void 0===l?void 0:l.onAuthorizeSuccess)&&(null===(u=null===(d=this.options)||void 0===d?void 0:d.events)||void 0===u||u.onAuthorizeSuccess(c))}catch(t){s.completePayment(ApplePaySession.STATUS_FAILURE),(null===(h=null===(c=this.options)||void 0===c?void 0:c.events)||void 0===h?void 0:h.onAuthorizeFailed)&&(null===(v=this.options)||void 0===v||v.events.onAuthorizeFailed(t))}},s.begin(),s}catch(t){return null}}async onApplePayAuthorized(t){const e={paymentData:t.paymentData,transactionIdentifier:t.transactionIdentifier,paymentNetwork:t.paymentMethod.network,paymentInstrumentName:t.paymentMethod.displayName},n=[{paymentMethodCode:"applePay",integrationType:"api",paymentInstrumentData:{paymentToken:JSON.stringify(e)},amount:this.sdkConfig.amount,storeInstrument:this.shouldStoreInstrument}];return await this.paymentExecutor.pay(n)}}const{CARD_NUMBER:C,CVV:w,CARDHOLDER_NAME:k,EXPIRATION_MONTH:A,EXPIRATION_YEAR:P}=exports.ElementType,x={base:{border:"none",padding:"10px 16px",color:"#1d1d1d",backgroundColor:"#fff"},invalid:{backgroundColor:"#f9e1e1",borderColor:"#f25226",border:"1px solid"}},E=[{type:k,placeholder:"Card holder",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{border:"1px solid #eae8ee",padding:"10px 16px",borderTopLeftRadius:"4px",borderTopRightRadius:"4px"})})},{type:C,placeholder:"1234 1234 1234 1234",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{border:"1px solid #eae8ee",padding:"10px 16px",borderTopLeftRadius:"4px",borderTopRightRadius:"4px",textIndent:"0"}),cardIcon:{position:"absolute",right:"8px",height:"24px",bottom:"calc(50% - 12px)"}})},{type:A,placeholder:"MM",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{borderBottom:"1px solid #eae8ee",borderLeft:"1px solid #eae8ee",borderRight:"1px solid #eae8ee",borderBottomLeftRadius:"4px"})})},{type:P,placeholder:"YY",format:"YY",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{borderBottom:"1px solid #eae8ee",borderRight:"1px solid #eae8ee"})})},{type:w,placeholder:"CVC",styles:Object.assign(Object.assign({},x),{base:Object.assign(Object.assign({},x.base),{borderBottom:"1px solid #eae8ee",borderRight:"1px solid #eae8ee",borderBottomRightRadius:"4px"})})}];class S extends b{constructor(t,e){var n,i,o,s,a;super("div",Object.assign(Object.assign({},e),{translations:Object.assign(Object.assign({},null==e?void 0:e.translations),{labels:Object.assign(Object.assign({},null===(n=null==e?void 0:e.translations)||void 0===n?void 0:n.labels),{saveInstrument:null===(o=null===(i=null==e?void 0:e.translations)||void 0===i?void 0:i.labels)||void 0===o?void 0:o.saveCreditCard})}),styles:Object.assign({storeInstrumentCheckbox:null===(s=null==e?void 0:e.styles)||void 0===s?void 0:s.storeCardCheckbox},null==e?void 0:e.styles),id:"payrails-card-form"})),this.collectContainer=t,this.options=e,this.formFields=[],(null===(a=null==e?void 0:e.styles)||void 0===a?void 0:a.storeCardCheckbox)&&console.warn("The `storeCardCheckbox` option for styles is deprecated. Please use `storeInstrumentCheckbox` instead."),E.forEach((({type:t,styles:n,format:i,placeholder:o})=>{var s,a,r,l,d,u,c;if(!(null===(s=this.options)||void 0===s?void 0:s.showCardHolderName)&&t===exports.ElementType.CARDHOLDER_NAME)return;const h=new I(this.collectContainer,{type:t,label:null===(r=null===(a=null==e?void 0:e.translations)||void 0===a?void 0:a.labels)||void 0===r?void 0:r[t],placeholder:(null===(d=null===(l=null==e?void 0:e.translations)||void 0===l?void 0:l.placeholders)||void 0===d?void 0:d[t])||o,labelStyles:this.prepareLabelStyles(t),inputStyles:this.prepareInputStyles(n,t),format:i,events:{onFocus:null===(c=null===(u=this.options)||void 0===u?void 0:u.events)||void 0===c?void 0:c.onFocus,onChange:this.onChange.bind(this)}});this.formFields.push(h)})),this.subElements.push(this.collectContainer),this.storeInstrumentCheckbox&&this.subElements.push(this.storeInstrumentCheckbox)}show(){this.element.style.display="flex"}hide(){this.element.style.display="none"}prepareLabelStyles(t){return["base"].reduce(((e,n)=>{var i,o,s,a,r,l,d,u;return e[n]=Object.assign(Object.assign(Object.assign({},null===(o=null===(i=this.options)||void 0===i?void 0:i.styles)||void 0===o?void 0:o.base),null===(r=null===(a=null===(s=this.options)||void 0===s?void 0:s.styles)||void 0===a?void 0:a.labels)||void 0===r?void 0:r.all),null===(u=null===(d=null===(l=this.options)||void 0===l?void 0:l.styles)||void 0===d?void 0:d.labels)||void 0===u?void 0:u[t]),e}),{})}prepareInputStyles(t,e){var n;let i=JSON.parse(JSON.stringify(t));return(null===(n=this.options)||void 0===n?void 0:n.showCardHolderName)&&e===exports.ElementType.CARD_NUMBER&&(this.element.setAttribute("class","with-card-holder"),i=Object.assign(Object.assign({},t),{base:Object.assign(Object.assign({},x.base),{border:"1px solid #eae8ee",borderTop:"none",padding:"10px 16px",textIndent:"0"})})),["base","complete","empty","focus","invalid","cardIcon","copyIcon"].forEach((t=>{var n,o,s,a,r,l,d,u;i[t]=Object.assign(Object.assign(Object.assign({},i[t]),null===(a=null===(s=null===(o=null===(n=this.options)||void 0===n?void 0:n.styles)||void 0===o?void 0:o.inputFields)||void 0===s?void 0:s.all)||void 0===a?void 0:a[t]),null===(u=null===(d=null===(l=null===(r=this.options)||void 0===r?void 0:r.styles)||void 0===l?void 0:l.inputFields)||void 0===d?void 0:d[e])||void 0===u?void 0:u[t])})),i}get isValid(){return this.formFields.reduce(((t,e)=>t&&e.isValid),!0)}get cardNetwork(){var t,e;return null!==(e=null===(t=this.formFields.find((t=>Boolean(t.cardNetwork))))||void 0===t?void 0:t.cardNetwork)&&void 0!==e?e:""}onChange(){var t,e,n,i;(null===(e=null===(t=this.options)||void 0===t?void 0:t.events)||void 0===e?void 0:e.onChange)&&(null===(i=null===(n=this.options)||void 0===n?void 0:n.events)||void 0===i||i.onChange({isValid:this.isValid,cardNetwork:this.cardNetwork}))}async collectValues(){var t;return{tokenizedCardData:await this.collectContainer.collect(),storeInstrument:this.shouldStoreInstrument,enrollInstrumentToNetworkOffers:Boolean(null===(t=this.options)||void 0===t?void 0:t.enrollInstrumentToNetworkOffers)}}}class I{constructor(t,e){this.isValid=!1,this.cardNetwork="";const{events:n}=e,i=t.createCollectElement(e);(null==n?void 0:n.onFocus)&&i.on("FOCUS",n.onFocus),i.on("CHANGE",(t=>{const{isEmpty:e,isValid:i,network:o}=t;this.isValid=!e&&i,this.cardNetwork=null!=o?o:"",(null==n?void 0:n.onChange)&&n.onChange(this)}))}}class O extends y{constructor(t,e){super("div",{id:"payrails-card-list"}),this.workflowExecution=t,this.listItems=[],this.workflowExecution.savedCreditCards.forEach((t=>{const n=new _((()=>{(null==e?void 0:e.onCardChange)&&e.onCardChange(t)}),t);this.listItems.push(n),this.subElements.push(n)}))}reset(){this.element.querySelectorAll("input").forEach((t=>t.checked=!1))}}class _ extends y{constructor(t,e){super("div",{className:"payrails-card-list-item",id:`payrails-card-list-item-${e.id}`});const{id:n}=e,i=this.createCardLabel(e),o=document.createElement("label");o.setAttribute("for",n),o.addEventListener("click",t);const s=document.createElement("input");s.setAttribute("type","radio"),s.setAttribute("name","payment-option"),s.setAttribute("id",n),s.setAttribute("value",n),o.appendChild(s);const a=document.createElement("span");a.innerText=i,o.appendChild(a),this.element.appendChild(o)}createCardLabel({data:t={}}){return`****${null==t?void 0:t.suffix}`}}var B,L;!function(t){t.CARD="card",t.GOOGLE_PAY="googlePay",t.PAYPAL="payPal",t.APPLE_PAY="applePay"}(B||(B={})),function(t){t.ENABLED="enabled",t.CREATED="created"}(L||(L={}));class T{constructor(t){this.executionResponse=t}get lookup(){return this.executionResponse.initialResults.find((({body:{name:t}})=>"lookup"===t))}get holderReference(){return this.executionResponse.holderReference}get savedCreditCards(){return this.getStoredInstrumentForPaymentMethod(B.CARD)}get savedPaypalAccounts(){return this.getStoredInstrumentForPaymentMethod(B.PAYPAL)}get savedGooglePayAccounts(){return this.getStoredInstrumentForPaymentMethod(B.GOOGLE_PAY)}get savedApplePayAccounts(){return this.getStoredInstrumentForPaymentMethod(B.APPLE_PAY)}get paypalConfig(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===B.PAYPAL));if(!t)throw new Error("trying to initialize paypal without config");return t.config||{}}get googlePayConfig(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===B.GOOGLE_PAY));if(!t)throw new Error("trying to initialize google pay without config");return t?[t.config]:[]}get applePayConfig(){const t=this.availablePaymentMethods.find((({paymentMethodCode:t})=>t===B.APPLE_PAY));if(!t)throw new Error("apple pay config not found");return t.config.parameters}get url(){return this.response.links.self}get response(){return this.executionResponse}get meta(){return this.executionResponse.meta}get availablePaymentMethods(){var t;return(null===(t=this.lookup)||void 0===t?void 0:t.body.data.paymentCompositionOptions)||[]}get authorizeLink(){var t;return null===(t=this.lookup)||void 0===t?void 0:t.body.links.authorize.href}get createSessionLink(){return this.response.links.startPaymentSession.href}get storedPaymentInstruments(){return this.availablePaymentMethods.flatMap((t=>t.paymentInstruments||[]))}getStoredInstrumentForPaymentMethod(t){var e;return(null===(e=this.availablePaymentMethods.find((({paymentMethodCode:e})=>e===t)))||void 0===e?void 0:e.paymentInstruments)||[]}}class j extends y{constructor(t,e,n,i){var o;super("button",{id:"payrails-card-payment-button"}),this.sdkConfig=t,this.execution=e,this.options=n,this.returnLinks=i,this.selectedCard=null,this.element.innerText=(null===(o=null==n?void 0:n.translations)||void 0===o?void 0:o.label)||"Pay",this.element.addEventListener("click",this.onPay.bind(this)),this.element.addEventListener("mouseenter",(()=>{var t;this.element.classList.contains("disabled")||(this.element.classList.add("hover"),this.setStyles((null===(t=this.options.styles)||void 0===t?void 0:t.hover)||{}))})),this.element.addEventListener("mouseleave",(()=>{var t;this.element.classList.contains("disabled")||(this.element.classList.remove("hover"),this.removeStyles((null===(t=this.options.styles)||void 0===t?void 0:t.hover)||{}))})),this.paymentExecutor=new p(this.sdkConfig,this.execution,this.returnLinks)}setDisabled(t){var e,n,i;this.element.disabled=t,t?(this.element.classList.add("disabled"),(null===(e=this.options.styles)||void 0===e?void 0:e.disabled)&&this.setStyles(this.options.styles.disabled)):(this.element.classList.remove("disabled"),this.removeStyles((null===(n=this.options.styles)||void 0===n?void 0:n.disabled)||{}),(null===(i=this.options.styles)||void 0===i?void 0:i.base)&&this.setStyles(this.options.styles.base))}setSavedCreditCard(t){console.warn("setSavedCreditCard is deprecated, please use setSavedInstrument"),this.setSavedInstrument(t)}setSavedInstrument(t){this.selectedCard=t,this.setDisabled(!1)}setStyles(t){var e;const n=Object.assign(Object.assign({},null===(e=this.options.styles)||void 0===e?void 0:e.base),t);Object.keys(n).forEach((t=>{this.element.style[t]=n[t]}))}removeStyles(t){var e;const n=Object.keys((null===(e=this.options.styles)||void 0===e?void 0:e.base)||{});Object.keys(t).forEach((t=>{var e,i;n.includes(t)?this.element.style[t]=null===(i=null===(e=this.options.styles)||void 0===e?void 0:e.base)||void 0===i?void 0:i[t]:this.element.style[t]=""}))}setLabel(t){this.element.innerText=t}setCardForm(t){this.cardForm=t}triggerLoading(t){var e,n,i,o;const s=this.element.offsetWidth;this.element.style.minWidth=`${s}px`,t?(this.element.innerHTML='<div class="dot-flashing"></div>',this.element.classList.add("loading"),(null===(e=this.options.styles)||void 0===e?void 0:e.loading)&&this.setStyles(this.options.styles.loading)):(this.element.innerText=(null===(i=null===(n=this.options)||void 0===n?void 0:n.translations)||void 0===i?void 0:i.label)||"Pay",this.element.classList.remove("loading"),this.removeStyles((null===(o=this.options.styles)||void 0===o?void 0:o.loading)||{}))}onAuthorizationFailed(){var t,e;this.setDisabled(!1),this.triggerLoading(!1),(null===(t=this.options.events)||void 0===t?void 0:t.onAuthorizeFailed)&&(null===(e=this.options.events)||void 0===e||e.onAuthorizeFailed())}async onPay(){var t,e,n,i,o,s,a,r;if(this.setDisabled(!0),this.triggerLoading(!0),null===(t=this.options.events)||void 0===t?void 0:t.onPaymentButtonClicked){if(!1===await(null===(e=this.options.events)||void 0===e?void 0:e.onPaymentButtonClicked()))return void this.onAuthorizationFailed()}try{const t=[{paymentMethodCode:B.CARD,integrationType:"api",amount:this.sdkConfig.amount,storeInstrument:!1}];if(null===(n=this.selectedCard)||void 0===n?void 0:n.id)t[0].paymentInstrumentId=null===(i=this.selectedCard)||void 0===i?void 0:i.id,t[0].paymentMethodCode=null===(o=this.selectedCard)||void 0===o?void 0:o.paymentMethod;else{const{tokenizedCardData:e,storeInstrument:n,enrollInstrumentToNetworkOffers:i}=await this.collectCardFormValues();t[0].paymentInstrumentData={vaultToken:null==e?void 0:e.instrumentId,card:{numberToken:null==e?void 0:e.card_number,securityCodeToken:null==e?void 0:e.security_code}},t[0].storeInstrument=n,t[0].enrollInstrumentToNetworkOffers=i}const e=await this.paymentExecutor.pay(t);this.handleAuthorizationResult(e)}catch(t){(t instanceof d||[401,403].includes(null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.code))&&(null===(r=null===(a=this.options.events)||void 0===a?void 0:a.onPaymentSessionExpired)||void 0===r||r.call(a)),this.onAuthorizationFailed()}}handleAuthorizationResult(t){var e,n,i;switch(null===(e=null==t?void 0:t.finalState)||void 0===e?void 0:e.code){case"authorizeSuccessful":this.triggerLoading(!1),(null===(n=this.options.events)||void 0===n?void 0:n.onAuthorizeSuccess)&&this.options.events.onAuthorizeSuccess();break;case"authorizePending":"3ds"===(null===(i=null==t?void 0:t.response)||void 0===i?void 0:i.actionRequired)&&this.handle3ds(t);break;default:this.onAuthorizationFailed()}}handle3ds(t){var e,n;const i=null===(e=null==t?void 0:t.response)||void 0===e?void 0:e.links["3ds"];if(i){const t=[[250,400],[390,400],[500,600],[600,400]],e=screen.width,o=t.reduce(((t,n)=>e>n[0]?n:t),[250,400]),s=document.createElement("iframe");s.setAttribute("id","payrails-3ds-frame"),s.setAttribute("src",i),s.setAttribute("width",o[0].toString()),s.setAttribute("height",o[1].toString());const a=document.createElement("div");a.setAttribute("id","payrails-3ds-challenge"),a.appendChild(s);const r=document.createElement("div");r.addEventListener("click",(async()=>{r.remove()})),r.setAttribute("id","payrails-3ds-popup-background"),r.appendChild(a);const l=async t=>{var e,n,i;if(t.data&&'{"type":"3DS-challenge-completed"}'===t.data){window.removeEventListener("message",l),r.remove();if(!(await this.paymentExecutor.getExecution(this.execution.url)).res.status.find((({code:t})=>"authorizeSuccessful"===t))&&(null===(e=this.options.events)||void 0===e?void 0:e.onAuthorizeFailed))return void this.onAuthorizationFailed();if(null===(n=this.options.events)||void 0===n?void 0:n.onAuthorizeSuccess)return void(null===(i=this.options.events)||void 0===i||i.onAuthorizeSuccess())}};null===(n=document.querySelector("body"))||void 0===n||n.appendChild(r),window.addEventListener("message",l),a.style.width=`${o[0]+4}px`,a.style.height=`${o[1]+4}px`}}async collectCardFormValues(){if(!this.cardForm)throw new Error("Trying to collect values from non-existent card form");return await this.cardForm.collectValues()}}class F extends y{constructor(t="Authorization failed, please try again."){super("div",{id:"authorization-failed-message"}),this.element.innerText=t,this.element.innerHTML=`\n <div>\n <svg class="checkmark-cross" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">\n <circle class="checkmark-cross_circle" cx="26" cy="26" r="25" fill="none"/>\n <path class="checkmark-cross_check" fill="none" d="M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8"/>\n </svg>\n </div>\n <div>${t}</div>`,this.element.addEventListener("click",(t=>{t.preventDefault(),t.stopImmediatePropagation(),t.stopPropagation(),this.unmount()}))}}class z extends y{constructor(t){var e;super("div",{id:"payrails-authorization-success-msg"}),this.element.innerHTML=`\n <div class="checkmark-wrapper">\n <svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">\n <circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>\n <path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>\n </svg>\n </div>\n <div id="payrails-authorization-success">${(null===(e=null==t?void 0:t.translations)||void 0===e?void 0:e.label)||"Payment successful"}</div`}}class R extends y{constructor(t,e,n){super("div",{id:t,className:"payrails-dropin-item"}),this.events=n,this.isActive=!1;const i=`payrails-dropin-item-${t}`,o=document.createElement("label");o.setAttribute("for",i);const s=document.createElement("input");s.setAttribute("type","radio"),s.setAttribute("name","payment-option"),s.setAttribute("id",i),s.setAttribute("value",i),this.input=s,o.appendChild(s),this.label=o;const a=document.createElement("span");o.appendChild(a),a.innerText=e,this.element.appendChild(o)}get identifier(){return`payrails-dropin-item-${this.id}`}deactivate(){var t,e;this.isActive&&(this.isActive=!1,this.label.style.marginBottom="0",null===(t=this.component)||void 0===t||t.unmount(),(null===(e=this.events)||void 0===e?void 0:e.onDeactivate)&&this.events.onDeactivate())}activate(){var t,e;this.isActive||(null===(t=this.component)||void 0===t||t.mount(this.selector),this.label.style.marginBottom="8px",this.isActive=!0,(null===(e=this.events)||void 0===e?void 0:e.onActivate)&&this.events.onActivate())}}class M extends R{constructor(){super(...arguments),this.buttonShown=!1}activate(){if(!this.buttonShown)return super.activate(),void(this.buttonShown=!0);this.label.style.marginBottom="8px",this.isActive=!0,this.element.querySelector(this.component.selector).style.display="block"}deactivate(){this.isActive&&(this.isActive=!1,this.label.style.marginBottom="0",this.element.querySelector(this.component.selector).style.display="none")}mountAfterAvailable(){super.mount(`#${this.loadElementId}`)}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);const n=document.createElement("div");n.setAttribute("id",this.loadElementId),n.setAttribute("style","width: 100%;"),e.appendChild(n)}unmount(){var t;super.unmount(),null===(t=document.querySelector(`#${this.loadElementId}`))||void 0===t||t.remove()}}class N extends M{constructor(t,e,n){var i,o;super("apple-pay-dropin",(null===(o=null===(i=n.translations)||void 0===i?void 0:i.labels)||void 0===o?void 0:o.label)||"Apple Pay"),this.loadElementId="apple-pay-dropin-load-element",this.component=new f(t,e,Object.assign(Object.assign({},n),{events:{onApplePayAvailable:()=>{this.mountAfterAvailable()}}}))}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);const n=document.createElement("div");n.setAttribute("id",this.loadElementId),n.setAttribute("style","width: 100%;"),e.appendChild(n)}}class D extends R{constructor(t,e){super("payrails-credit-card-wrapper","Card"),this.cardForm=t,this.paymentButton=e,this.cardFormShown=!1,this.component=new $(t,e)}activate(){var t,e;this.label.style.marginBottom="8px",this.cardFormShown||(this.cardFormShown=!0,null===(t=this.component)||void 0===t||t.mount(this.selector)),this.isActive||(this.paymentButton.selectedCard=null,this.paymentButton.mount(this.selector),this.paymentButton.setDisabled(!this.cardForm.isValid),this.paymentButton.mount("#payrails-card-form"),this.input.checked=!0,this.cardForm.show(),this.isActive=!0,(null===(e=this.events)||void 0===e?void 0:e.onActivate)&&this.events.onActivate())}deactivate(){var t;this.isActive&&(this.label.style.marginBottom="0",this.paymentButton.unmount(),this.cardForm.hide(),this.isActive=!1,(null===(t=this.events)||void 0===t?void 0:t.onDeactivate)&&this.events.onDeactivate())}}class $ extends y{constructor(t,e){super("div",{id:"payrails-form-container"}),this.subElements.push(t,e)}}const U={apiVersion:2,apiVersionMinor:0};class V extends b{constructor(t,e,n){super("div",Object.assign(Object.assign({},n),{id:"payrails-google-pay-button"})),this.sdkConfig=t,this.execution=e,this.options=n,this.googleButton=null,this.paymentExecutor=new p(t,e),this.loadScript=new m((async()=>{const t=document.createElement("script");return t.src="https://pay.google.com/gp/p/js/pay.js",new Promise(((e,n)=>{t.onload=()=>{const t=new google.payments.api.PaymentsClient({environment:this.options.environment||"TEST"}),i=Object.assign(Object.assign({},U),{allowedPaymentMethods:this.execution.googlePayConfig});t.isReadyToPay(i).then((i=>{var o,s,a;i?(null===(a=null===(s=null===(o=this.options)||void 0===o?void 0:o.events)||void 0===s?void 0:s.onGooglePayAvailable)||void 0===a||a.call(s),e(t)):n()}),n)},t.onerror=()=>{n()},document.body.appendChild(t)}))}))}async sdkLoaded(t){var e,n,i,o,s,a,r,l;try{const d=(null===(n=null===(e=this.options)||void 0===e?void 0:e.styles)||void 0===n?void 0:n.buttonColor)||"black",u=(null===(o=null===(i=this.options)||void 0===i?void 0:i.styles)||void 0===o?void 0:o.buttonType)||"long",c=(null===(a=null===(s=this.options)||void 0===s?void 0:s.styles)||void 0===a?void 0:a.buttonSizeMode)||"fill",h=(null===(l=null===(r=this.options)||void 0===r?void 0:r.styles)||void 0===l?void 0:l.buttonLocale)||void 0;return this.googleButton=t.createButton({buttonColor:d,buttonType:u,buttonSizeMode:c,buttonLocale:h,onClick:async()=>{var t,e,n;if(null===(e=null===(t=this.options)||void 0===t?void 0:t.events)||void 0===e?void 0:e.onPaymentButtonClicked){if(!await(null===(n=this.options)||void 0===n?void 0:n.events.onPaymentButtonClicked()))return}await this.onPaymentButtonClicked()},allowedPaymentMethods:this.execution.googlePayConfig}),this.element.appendChild(this.googleButton),this.googleButton}catch(t){throw console.error("Google pay can not be initialized",t),new Error(t.message)}}async onLoadPaymentData(t){var e,n,i,o;const s=[{paymentMethodCode:"googlePay",integrationType:"api",paymentInstrumentData:{paymentToken:t.paymentMethodData.tokenizationData.token},amount:this.sdkConfig.amount,storeInstrument:this.shouldStoreInstrument}],a=await this.paymentExecutor.pay(s);(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onAuthorizeSuccess)&&(null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o||o.onAuthorizeSuccess(a))}async onPaymentButtonClicked(){var t,e,n,i,o;const s=Object.assign({},U);s.allowedPaymentMethods=this.execution.googlePayConfig,s.transactionInfo={totalPriceStatus:"FINAL",totalPrice:null===(t=this.sdkConfig.amount)||void 0===t?void 0:t.value,currencyCode:null===(e=this.sdkConfig.amount)||void 0===e?void 0:e.currency,countryCode:null===(o=null===(i=null===(n=this.execution.meta)||void 0===n?void 0:n.customer)||void 0===i?void 0:i.country)||void 0===o?void 0:o.code};(await this.loadScript.loader).loadPaymentData(s).then((t=>{this.onLoadPaymentData(t)})).catch((t=>{var e,n,i;(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onAuthorizeFailed)&&(null===(i=this.options)||void 0===i||i.events.onAuthorizeFailed(t))}))}mount(t){super.mount(t),(async()=>{var t;try{const e=await this.loadScript.loader,n=await this.sdkLoaded(e);this.element.appendChild(n),null===(t=this.storeInstrumentCheckbox)||void 0===t||t.mount(this.selector)}catch(t){}})()}unmount(){var t,e,n;null===(e=null===(t=this.googleButton)||void 0===t?void 0:t.parentElement)||void 0===e||e.removeChild(this.googleButton),null===(n=this.storeInstrumentCheckbox)||void 0===n||n.unmount(),super.unmount()}}class G extends M{constructor(t,e,n){var i,o;super("google-pay-dropin",(null===(o=null===(i=n.translations)||void 0===i?void 0:i.labels)||void 0===o?void 0:o.label)||"Google Pay"),this.loadElementId="google-pay-dropin-load-element",this.component=new V(t,e,Object.assign(Object.assign({},n),{events:Object.assign(Object.assign({},n.events),{onGooglePayAvailable:()=>{this.mountAfterAvailable()}})}))}mount(t){const e=document.querySelector(t);if(!e)throw new Error(`Element with selector "${t}" not found in in the DOM`);const n=document.createElement("div");n.setAttribute("id",this.loadElementId),n.setAttribute("style","width: 100%;"),e.appendChild(n)}}
2
2
  /*!
3
3
  * paypal-js v5.1.4 (2022-11-29T23:08:21.847Z)
4
4
  * Copyright 2020-present, PayPal, Inc. All rights reserved.
@@ -14,4 +14,4 @@
14
14
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
- */function H(t){var e="https://www.paypal.com/sdk/js";t.sdkBaseURL&&(e=t.sdkBaseURL,delete t.sdkBaseURL),function(t){var e=t["merchant-id"],n=t["data-merchant-id"],i="",o="";Array.isArray(e)?e.length>1?(i="*",o=e.toString()):i=e.toString():"string"==typeof e&&e.length>0?i=e:"string"==typeof n&&n.length>0&&(i="*",o=n);t["merchant-id"]=i,t["data-merchant-id"]=o}(t);var n=Object.keys(t).filter((function(e){return void 0!==t[e]&&null!==t[e]&&""!==t[e]})).reduce((function(e,n){var i=t[n].toString();return"data-"===n.substring(0,5)?e.dataAttributes[n]=i:e.queryParams[n]=i,e}),{queryParams:{},dataAttributes:{}}),i=n.queryParams,o=n.dataAttributes;return{url:"".concat(e,"?").concat(q(i)),dataAttributes:o}}function q(t){var e="";return Object.keys(t).forEach((function(n){0!==e.length&&(e+="&"),e+=n+"="+t[n]})),e}function G(t,e){void 0===e&&(e={});var n=document.createElement("script");return n.src=t,Object.keys(e).forEach((function(t){n.setAttribute(t,e[t]),"data-csp-nonce"===t&&n.setAttribute("nonce",e["data-csp-nonce"])})),n}function Y(t,e){if(void 0===e&&(e=W()),J(t,e),"undefined"==typeof window)return e.resolve(null);var n=H(t),i=n.url,o=n.dataAttributes,s=o["data-namespace"]||"paypal",a=X(s);return function(t,e){var n=document.querySelector('script[src="'.concat(t,'"]'));if(null===n)return null;var i=G(t,e),o=n.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(i.dataset).length)return null;var s=!0;return Object.keys(o.dataset).forEach((function(t){o.dataset[t]!==i.dataset[t]&&(s=!1)})),s?n:null}(i,o)&&a?e.resolve(a):function(t,e){void 0===e&&(e=W());J(t,e);var n=t.url,i=t.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==i&&"object"!=typeof i)throw new Error("Expected attributes to be an object.");return new e((function(t,e){if("undefined"==typeof window)return t();!function(t){var e=t.url,n=t.attributes,i=t.onSuccess,o=t.onError,s=G(e,n);s.onerror=o,s.onload=i,document.head.insertBefore(s,document.head.firstElementChild)}({url:n,attributes:i,onSuccess:function(){return t()},onError:function(){var t=new Error('The script "'.concat(n,'" failed to load.'));return window.fetch?fetch(n).then((function(n){return 200===n.status&&e(t),n.text()})).then((function(t){var n=function(t){var e=t.split("/* Original Error:")[1];return e?e.replace(/\n/g,"").replace("*/","").trim():t}(t);e(new Error(n))})).catch((function(t){e(t)})):e(t)}})}))}({url:i,attributes:o},e).then((function(){var t=X(s);if(t)return t;throw new Error("The window.".concat(s," global variable is not available."))}))}function W(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function X(t){return window[t]}function J(t,e){if("object"!=typeof t||null===t)throw new Error("Expected an options object.");if(void 0!==e&&"function"!=typeof e)throw new Error("Expected PromisePonyfill to be a function.")}class K extends y{constructor(t,e,n){super("div",{id:"payrails-paypal-button"}),this.sdkConfig=t,this.execution=e,this.options=n,this.paypalLoader=null,this.storeInstrumentCheckbox=null,this.buttonWrapperId="payrails-paypal-button-wrapper",this.checkboxWrapperId="payrails-paypal-checkbox-wrapper",this.createOneTimeOrder=async()=>{var t,e,n,i,o,s,a;const r=[{paymentMethodCode:"payPal",integrationType:"api",amount:this.sdkConfig.amount,paymentInstrumentData:{providerData:{merchantId:this.execution.paypalConfig.merchantId,fraudNetGuid:this.fraudNetGuid}},storeInstrument:!1}],l=await this.paymentExecutor.pay(r),d=null===(n=null===(e=null===(t=l.response.links.confirm)||void 0===t?void 0:t.action)||void 0===e?void 0:e.parameters)||void 0===n?void 0:n.orderId;if(!d)throw null===(s=null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o?void 0:o.onAuthorizeFailed)||void 0===s||s.call(o),new Q("No order id returned");return this.confirmLink=null===(a=l.response.links.confirm)||void 0===a?void 0:a.href,d},this.element.innerHTML=`<div id="${this.buttonWrapperId}"></div><div id="${this.checkboxWrapperId}"></div>`,this.paymentExecutor=new v(t,e),this.paypalLoader=new m(this.loadPaypal.bind(this)),this.fraudNetGuid=null==n?void 0:n.fraudNetGuid}get isBillingAgreement(){var t,e;return(null===(t=this.storeInstrumentCheckbox)||void 0===t?void 0:t.isChecked)||(null===(e=this.options)||void 0===e?void 0:e.alwaysStoreInstrument)||!1}async loadPaypal(){const t=this.execution.paypalConfig,e=await Y({"client-id":t.clientId,components:"buttons,funding-eligibility",intent:this.isBillingAgreement?"tokenize":"authorize",currency:this.sdkConfig.amount.currency,vault:this.isBillingAgreement});if(e){return await this.createPaypalButton(e)}throw new Error("Paypal not available")}async createPaypalButton(t){var e,n,i;if(!t.Buttons)throw new Error("Paypal button not available");const o=await t.Buttons(this.createPayPalButtonConfig());return o.isEligible()?(null===(i=null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onPaypalAvailable)||void 0===i||i.call(n),o):null}createPayPalButtonConfig(){return this.isBillingAgreement?this.createBillingAgreementConfig():this.createOneTimeOrderConfig()}createBillingAgreementConfig(){return Object.assign(Object.assign({},this.createBaseConfig()),{onApprove:this.approvePayment.bind(this),createBillingAgreement:async()=>{var t,e,n,i;const o=[{paymentMethodCode:"payPal",integrationType:"api",amount:this.sdkConfig.amount,paymentInstrumentData:{providerData:{merchantId:this.execution.paypalConfig.merchantId,fraudNetGuid:this.fraudNetGuid}},storeInstrument:!0}],s=await this.paymentExecutor.pay(o);return this.confirmLink=null===(t=s.response.links.confirm)||void 0===t?void 0:t.href,(null===(i=null===(n=null===(e=s.response.links.confirm)||void 0===e?void 0:e.action)||void 0===n?void 0:n.parameters)||void 0===i?void 0:i.tokenId)||""}})}createOneTimeOrderConfig(){return Object.assign(Object.assign({},this.createBaseConfig()),{createOrder:this.createOneTimeOrder.bind(this),onApprove:this.approvePayment.bind(this)})}createBaseConfig(){var t,e,n,i,o,s,a,r,l,d;return{fundingSource:"paypal",style:{color:(null===(e=null===(t=this.options)||void 0===t?void 0:t.styles)||void 0===e?void 0:e.color)||"gold",height:(null===(i=null===(n=this.options)||void 0===n?void 0:n.styles)||void 0===i?void 0:i.height)||40,label:(null===(s=null===(o=this.options)||void 0===o?void 0:o.styles)||void 0===s?void 0:s.label)||"paypal",shape:(null===(r=null===(a=this.options)||void 0===a?void 0:a.styles)||void 0===r?void 0:r.shape)||"rect",tagline:(null===(d=null===(l=this.options)||void 0===l?void 0:l.styles)||void 0===d?void 0:d.tagline)||!1},onError:t=>{var e,n;(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onAuthorizeFailed)&&this.options.events.onAuthorizeFailed(t)},onClick:async(t,e)=>{var n,i;if(null===(i=null===(n=this.options)||void 0===n?void 0:n.events)||void 0===i?void 0:i.onPaymentButtonClicked){return await this.options.events.onPaymentButtonClicked()?e.resolve():e.reject()}}}}async approvePayment(t){var e,n,i,o,s,a,r;if(!this.confirmLink)throw new Q("No confirm link");const l={};this.isBillingAgreement&&t.billingToken&&(l.tokenId=t.billingToken);"authorizeSuccessful"===(null===(e=(await this.paymentExecutor.confirm(this.confirmLink,l)).finalState)||void 0===e?void 0:e.code)?null===(o=null===(i=null===(n=this.options)||void 0===n?void 0:n.events)||void 0===i?void 0:i.onAuthorizeSuccess)||void 0===o||o.call(i):null===(r=null===(a=null===(s=this.options)||void 0===s?void 0:s.events)||void 0===a?void 0:a.onAuthorizeFailed)||void 0===r||r.call(a)}mount(t){super.mount(t),(async()=>{var t,e,n,i;this.paypalLoader||(this.paypalLoader=new m(this.loadPaypal.bind(this)));const o=await this.paypalLoader.loader;this.button=o;try{(null===(t=this.options)||void 0===t?void 0:t.showStoreInstrumentCheckbox)&&(this.storeInstrumentCheckbox=new f({id:"payrails-store-paypal",label:null===(n=null===(e=this.options.translations)||void 0===e?void 0:e.labels)||void 0===n?void 0:n.saveInstrument,styles:null===(i=this.options.styles)||void 0===i?void 0:i.storeInstrumentCheckbox,events:{onSaveInstrumentCheckboxChanged:async t=>{var e,n,i,o,s;null===(e=this.button)||void 0===e||e.close(),this.paypalLoader=null,this.paypalLoader=new m(this.loadPaypal.bind(this)),this.button=await this.paypalLoader.loader,this.button.render(`#${this.buttonWrapperId}`),(null===(i=null===(n=this.options)||void 0===n?void 0:n.events)||void 0===i?void 0:i.onSaveInstrumentCheckboxChanged)&&(null===(s=null===(o=this.options)||void 0===o?void 0:o.events)||void 0===s||s.onSaveInstrumentCheckboxChanged(t))}}}),this.storeInstrumentCheckbox.mount(`#${this.checkboxWrapperId}`)),await(null==o?void 0:o.render(`#${this.buttonWrapperId}`))}catch(t){throw new Z(t.message)}})()}unmount(){var t;null===(t=this.button)||void 0===t||t.close(),this.paypalLoader=null,super.unmount()}}class Q extends Error{constructor(t){super(`PaypalOrderError: ${t}`),this.name="PaypalOrderError"}}class Z extends Error{constructor(t){super(`PaypalButtonError: ${t}`),this.name="PaypalButtonError"}}class tt extends R{constructor(t,e,n){var i,o;super("payrails-paypal-button-dropin",(null===(o=null===(i=null==n?void 0:n.translations)||void 0===i?void 0:i.labels)||void 0===o?void 0:o.label)||"PayPal"),this.loadElementId="paypal-dropin-load-element",this.component=new K(t,e,Object.assign(Object.assign({},n),{events:Object.assign(Object.assign({},null==n?void 0:n.events),{onPaypalAvailable:()=>{this.mountAfterAvailable()}})}))}}class et extends j{constructor(t,e,n){super(`card-${t.id}`,`****${t.data.suffix}`,{onActivate:()=>{n(t),this.component.setDisabled(!1)}}),this.component=e}}class nt extends y{constructor(t,e,n,i){var o,s;super("fieldset",{id:"payrails-dropin-component"}),this.collectContainer=t,this.dropinConfig=e,this.execution=n,this.sdkConfig=i;const a=!1===(null===(s=null===(o=this.dropinConfig.paymentMethodsConfiguration)||void 0===o?void 0:o.cards)||void 0===s?void 0:s.showExistingCards),r=new Map;this.execution.availablePaymentMethods.forEach((({paymentMethodCode:t})=>{if(t===I.CARD)a||this.execution.savedCreditCards.forEach((t=>{var e;this.cardPaymentButton=this.createCardPaymentButton(null===(e=this.dropinConfig.translations)||void 0===e?void 0:e.cardPaymentButton);const n=new et(t,this.cardPaymentButton,(t=>{this.cardPaymentButton&&(this.cardPaymentButton.selectedCard=t)}));r.set(n.identifier,n)}))})),this.execution.availablePaymentMethods.forEach((({paymentMethodCode:t})=>{var e,n,i,o;switch(t){case I.PAYPAL:this.paypal=new tt(this.sdkConfig,this.execution,Object.assign(Object.assign({},null===(e=this.dropinConfig.paymentMethodsConfiguration)||void 0===e?void 0:e.paypal),{styles:null===(n=this.dropinConfig.styles)||void 0===n?void 0:n.paypalButton,events:{onAuthorizeSuccess:this.onAuthorizeSuccess.bind(this),onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onSaveInstrumentCheckboxChanged:t=>{this.dropinConfig.events.onSaveInstrumentCheckboxChanged&&this.dropinConfig.events.onSaveInstrumentCheckboxChanged(t)}}})),r.set(this.paypal.identifier,this.paypal);break;case I.CARD:this.creditCard=new D(this.createCardForm(),this.createCardPaymentButton(null===(i=this.dropinConfig.translations)||void 0===i?void 0:i.cardPaymentButton)),r.set(this.creditCard.identifier,this.creditCard);break;case I.GOOGLE_PAY:this.googlePay=new V(this.sdkConfig,this.execution,{events:{onAuthorizeSuccess:t=>{var e;if(t)if("authorizeSuccessful"===(null===(e=null==t?void 0:t.finalState)||void 0===e?void 0:e.code))this.onAuthorizeSuccess();else this.onAuthorizeFailed()},onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked},styles:null===(o=this.dropinConfig.styles)||void 0===o?void 0:o.googlePayButton}),r.set(this.googlePay.identifier,this.googlePay);break;case I.APPLE_PAY:this.applePay=new N(this.sdkConfig,this.execution,{events:{onAuthorizeSuccess:t=>{var e;if(t)if("authorizeSuccessful"===(null===(e=null==t?void 0:t.finalState)||void 0===e?void 0:e.code))this.onAuthorizeSuccess();else this.onAuthorizeFailed()},onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked}}),r.set(this.applePay.identifier,this.applePay)}})),this.element.addEventListener("change",(t=>{var e,n;const i=(null===(e=null==t?void 0:t.target)||void 0===e?void 0:e.value)||"";r.forEach((t=>{t.deactivate()})),null===(n=r.get(i))||void 0===n||n.activate()})),this.subElements.push(...Array.from(r.values()))}createCardForm(){var t,e;if(!this.cardForm){const n=null===(t=this.dropinConfig.paymentMethodsConfiguration)||void 0===t?void 0:t.cards,i=Boolean(null==n?void 0:n.showStoreInstrumentCheckbox),o=Boolean(null==n?void 0:n.showCardHolderName),s=Boolean(null==n?void 0:n.alwaysStoreInstrument);this.cardForm=new E(this.collectContainer,{showStoreInstrumentCheckbox:i,showCardHolderName:o,alwaysStoreInstrument:s,translations:null===(e=this.dropinConfig.translations)||void 0===e?void 0:e.cardForm,events:{onFocus:()=>{var t;null===(t=this.creditCard)||void 0===t||t.activate()},onChange:({isValid:t})=>{var e;null===(e=this.cardPaymentButton)||void 0===e||e.setDisabled(!t)},onSaveInstrumentCheckboxChanged:t=>{this.dropinConfig.events.onSaveInstrumentCheckboxChanged&&this.dropinConfig.events.onSaveInstrumentCheckboxChanged(t)}}})}return this.cardPaymentButton&&this.cardPaymentButton.setCardForm(this.cardForm),this.cardForm}createCardPaymentButton(t){return this.cardPaymentButton||(this.cardPaymentButton=new L(this.sdkConfig,this.execution,{translations:t,events:{onAuthorizeSuccess:this.onAuthorizeSuccess.bind(this),onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked,onPaymentSessionExpired:this.dropinConfig.events.onPaymentSessionExpired}})),this.cardForm&&this.cardPaymentButton.setCardForm(this.cardForm),this.cardPaymentButton}onAuthorizeSuccess(){var t,e,n,i;this.subElements.forEach((t=>t.unmount())),new F({translations:{label:null===(n=null===(e=null===(t=this.dropinConfig)||void 0===t?void 0:t.translations)||void 0===e?void 0:e.paymentResult)||void 0===n?void 0:n.success}}).mount(this.selector),(null===(i=this.dropinConfig.events)||void 0===i?void 0:i.onAuthorizeSuccess)&&this.dropinConfig.events.onAuthorizeSuccess()}onAuthorizeFailed(){var t,e,n;new z(null===(e=null===(t=this.dropinConfig.translations)||void 0===t?void 0:t.paymentResult)||void 0===e?void 0:e.fail).mount(this.selector),this.dropinConfig.events.onAuthorizeFailed&&(null===(n=this.dropinConfig.events)||void 0===n||n.onAuthorizeFailed())}}const it={visa:/^4\d*/,mastercard:/^(5[1-5]|222[1-9]|22[3-9]|2[3-6]|27[0-1]|2720)\d*/,amex:/^3[47]\d*/,diners:/^(36|38|30[0-5])\d*/,discover:/^(6011|65|64[4-9]|622)\d*/,jcb:/^35\d*/,hipercard:/^606282\d*/,unionpay:/^62\d*/,maestro:/^(5018|5020|5038|5043|5[6-9]|6020|6304|6703|6759|676[1-3])\d*/};class ot{constructor(t,e,n){this.sdkConfig=n,this.containerType="COMPOSABLE",this.cardTableName=e.cardTableName||"cards",this.containerType=e.containerType||"COMPOSABLE",this.__container=t.container(this.containerType,e)}get elementToFieldMap(){return new Map([[exports.ElementType.CARD_NUMBER,"card_number"],[exports.ElementType.CARDHOLDER_NAME,"cardholder_name"],[exports.ElementType.CVV,"security_code"],[exports.ElementType.EXPIRATION_MONTH,"expiry_month"],[exports.ElementType.EXPIRATION_YEAR,"expiry_year"]])}createCollectElement(t){const e={required:!!t.required,enableCardIcon:!!t.enableCardIcon},n=this.__container.create(Object.assign(Object.assign({table:this.cardTableName,labelStyles:{},errorTextStyles:{},column:this.elementToFieldMap.get(t.type)},t),{type:t.type===exports.ElementType.CARDHOLDER_NAME?"INPUT_FIELD":t.type}),t.format?Object.assign(Object.assign({},e),{format:t.format}):e);return this.attachCustomEventHandler(n)}mount(t){if("COLLECT"===this.containerType)throw new Error("Collect container cannot be mounted");const e="payrails-container-wrapper";this.element=document.createElement("span"),this.element.setAttribute("id",e);const n=document.querySelector(t);if(!n)throw new Error(`Element with selector ${t} does not exist`);n.appendChild(this.element),window.setTimeout((()=>{this.__container.mount(`#${e}`)}),50)}unmount(){this.element&&this.element.remove()}async collect(){const{records:t}=await this.__container.collect(),{skyflow_id:e,card_number:n,cardholder_name:i,expiry_month:o,expiry_year:s,security_code:a}=t[0].fields;return{instrumentId:e,card_number:n,cardholder_name:i,expiry_month:o,expiry_year:s,security_code:a}}async tokenize(t){const e=await this.collect(),{instrumentId:n,card_number:i,cardholder_name:o,expiry_month:a,expiry_year:r,security_code:d}=e,u=this.sdkConfig.vaultConfiguration.links.saveInstrument.href,c=this.sdkConfig.token,h=this.sdkConfig.holderReference;if(!u)throw new Error("Save instrument URL not available!");const p=await(({url:t,token:e,instrumentId:n,holderReference:i,providerId:o,providerConfigId:a,meta:r,storeInstrument:d=!1,futureUsage:u="CardOnFile"})=>l({url:t,token:e,method:s.POST,body:{holderReference:i,storeInstrument:d,futureUsage:u,paymentMethod:"card",token:{providerId:o,providerConfigId:a,reference:n,type:"vault",meta:r}}}))({url:u,token:c,instrumentId:n,holderReference:h,providerId:this.sdkConfig.vaultConfiguration.providerId,providerConfigId:this.sdkConfig.vaultConfiguration.providerConfigId,meta:{skyflow_id:n,card_number:i,cardholder_name:o,expiry_month:a,expiry_year:r,security_code:d},storeInstrument:t.storeInstrument||!1,futureUsage:t.futureUsage||"CardOnFile"});return p.res}attachCustomEventHandler(t){return new Proxy(t,{get(t,e){if("on"!==e)return t[e];return((n,i)=>{t[e].call(t,n,(t=>{"CHANGE"===n?(t.elementType===exports.ElementType.CARD_NUMBER&&(t.network=function(t){for(const[e,n]of Object.entries(it))if(n.test(t))return e;return""}(t.value)),i(t)):i(t)}))}).bind(t)}})}}class st{constructor(t,e,n){this.pageId=t,this.sdkConfig=e,this.environment=n,this.guid=r().replace(/-/g,""),this.fnclsVal="fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99",this.configId=r(),this.scriptId=r(),this.execution=new T(e.execution)}mount(){this.loadFraudnet(this.pageId)}unmount(){var t,e;null===(t=document.getElementById(this.configId))||void 0===t||t.remove(),null===(e=document.getElementById(this.scriptId))||void 0===e||e.remove()}loadFraudnet(t){this.unmount();const e=this.createFraudnetConfig(t);document.body.appendChild(e);const n=document.createElement("script");n.setAttribute("id",this.scriptId),n.src="https://c.paypal.com/da/r/fb.js",document.body.appendChild(n)}get payPalConfig(){return this.execution.paypalConfig}createFraudnetConfig(t){const e=document.createElement("script");return e.setAttribute("type","application/json"),e.setAttribute("fncls",this.fnclsVal),e.setAttribute("id",this.configId),e.innerText=JSON.stringify({f:this.guid,s:`${this.payPalConfig.merchantId}_${t}`,sandbox:"TEST"===this.environment}),e}}var at=require("skyflow-js").default;class rt{static init(t,e){const n=JSON.parse(atob(t.data)),{vaultConfiguration:{vaultId:i,vaultUrl:o,token:s},execution:a}=n,r=at.init({vaultID:i,vaultURL:o,getBearerToken:()=>Promise.resolve(s)});return new rt(n,r,new T(a),e)}update(t){this.sdkConfiguration.amount=t}collectContainer(t){if("COMPOSABLE"===t.containerType&&!t.layout)throw new Error("Layout configuration is required");return this.__container=new ot(this.vaultClient,Object.assign(Object.assign({},t),{cardTableName:this.sdkConfiguration.vaultConfiguration.cardTableName}),this.sdkConfiguration),this.__container}googlePayButton(t){var e;if(!this.execution)throw new Error("SDK was not initialized with workflow execution");return new U(this.sdkConfiguration,this.execution,Object.assign({environment:null===(e=this.options)||void 0===e?void 0:e.environment},t))}applePayButton(t){if(!this.execution)throw new Error("SDK was not initialized with workflow execution");return new g(this.sdkConfiguration,this.execution,t)}cardList(t){return this.__cardList||(this.__cardList=new _(this.execution,{onCardChange:e=>{this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=e,this.__cardPaymentButton.setDisabled(!1)),null==t||t.onCardChange(e)}})),this.__cardList}cardForm(t){var e,n;if(!this.__cardForm){const i=this.getContainerLayout(null==t?void 0:t.showCardHolderName);this.__container=this.collectContainer(Object.assign(Object.assign({layout:i,errorTextStyles:{base:{display:"none"}}},null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.errorTextStyles),{styles:{base:null===(n=null==t?void 0:t.styles)||void 0===n?void 0:n.base}})),this.__cardForm=new E(this.__container,Object.assign(Object.assign({},t),{events:Object.assign(Object.assign({},null==t?void 0:t.events),{onChange:e=>{var n;this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=null,this.__cardForm&&this.__cardPaymentButton.setDisabled(!this.__cardForm.isValid)),(null===(n=null==t?void 0:t.events)||void 0===n?void 0:n.onChange)&&t.events.onChange(e)},onFocus:()=>{var e;this.__cardList&&this.__cardList.reset(),this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=null,this.__cardForm&&this.__cardPaymentButton.setDisabled(!this.__cardForm.isValid)),(null===(e=null==t?void 0:t.events)||void 0===e?void 0:e.onFocus)&&t.events.onFocus()}})}))}return this.__cardPaymentButton&&this.__cardPaymentButton.setCardForm(this.__cardForm),this.__cardForm}dropin(t){var e,n;const i=this.getContainerLayout(null===(n=null===(e=t.paymentMethodsConfiguration)||void 0===e?void 0:e.cards)||void 0===n?void 0:n.showCardHolderName);return this.__container=this.collectContainer({layout:i,errorTextStyles:{base:{display:"none"}}}),new nt(this.__container,t,this.execution,this.sdkConfiguration)}getSavedCreditCards(){return this.execution.savedCreditCards}paymentButton(t){return this.__cardPaymentButton||(this.__cardPaymentButton=new L(this.sdkConfiguration,this.execution,t)),this.__cardPaymentButton.setDisabled(!0),this.__cardForm&&this.__cardPaymentButton.setCardForm(this.__cardForm),this.__cardPaymentButton}paypalButton(t){var e;return this.__paypalButton=new K(this.sdkConfiguration,this.execution,Object.assign(Object.assign({},t),{fraudNetGuid:(null==t?void 0:t.fraudNetGuid)||(null===(e=this.__fraudNet)||void 0===e?void 0:e.guid)})),this.__paypalButton}getSavedPaypalAccounts(){return this.execution.savedPaypalAccounts||[]}fraudNet(t){var e;return this.__fraudNet||(this.__fraudNet=new st(t,this.sdkConfiguration,(null===(e=this.options)||void 0===e?void 0:e.environment)||"TEST")),this.__paypalButton&&(this.__paypalButton.fraudNetGuid=this.__fraudNet.guid),this.__fraudNet}constructor(t,e,n,i){var o;this.sdkConfiguration=t,this.vaultClient=e,this.execution=n,this.options=i,(null===(o=null==i?void 0:i.events)||void 0===o?void 0:o.onClientInitialized)&&i.events.onClientInitialized(this.execution)}getContainerLayout(t){return t?[1,1,3]:[1,3]}}exports.Payrails=rt}();
17
+ */function H(t){var e="https://www.paypal.com/sdk/js";t.sdkBaseURL&&(e=t.sdkBaseURL,delete t.sdkBaseURL),function(t){var e=t["merchant-id"],n=t["data-merchant-id"],i="",o="";Array.isArray(e)?e.length>1?(i="*",o=e.toString()):i=e.toString():"string"==typeof e&&e.length>0?i=e:"string"==typeof n&&n.length>0&&(i="*",o=n);t["merchant-id"]=i,t["data-merchant-id"]=o}(t);var n=Object.keys(t).filter((function(e){return void 0!==t[e]&&null!==t[e]&&""!==t[e]})).reduce((function(e,n){var i=t[n].toString();return"data-"===n.substring(0,5)?e.dataAttributes[n]=i:e.queryParams[n]=i,e}),{queryParams:{},dataAttributes:{}}),i=n.queryParams,o=n.dataAttributes;return{url:"".concat(e,"?").concat(q(i)),dataAttributes:o}}function q(t){var e="";return Object.keys(t).forEach((function(n){0!==e.length&&(e+="&"),e+=n+"="+t[n]})),e}function Y(t,e){void 0===e&&(e={});var n=document.createElement("script");return n.src=t,Object.keys(e).forEach((function(t){n.setAttribute(t,e[t]),"data-csp-nonce"===t&&n.setAttribute("nonce",e["data-csp-nonce"])})),n}function W(t,e){if(void 0===e&&(e=X()),K(t,e),"undefined"==typeof window)return e.resolve(null);var n=H(t),i=n.url,o=n.dataAttributes,s=o["data-namespace"]||"paypal",a=J(s);return function(t,e){var n=document.querySelector('script[src="'.concat(t,'"]'));if(null===n)return null;var i=Y(t,e),o=n.cloneNode();if(delete o.dataset.uidAuto,Object.keys(o.dataset).length!==Object.keys(i.dataset).length)return null;var s=!0;return Object.keys(o.dataset).forEach((function(t){o.dataset[t]!==i.dataset[t]&&(s=!1)})),s?n:null}(i,o)&&a?e.resolve(a):function(t,e){void 0===e&&(e=X());K(t,e);var n=t.url,i=t.attributes;if("string"!=typeof n||0===n.length)throw new Error("Invalid url.");if(void 0!==i&&"object"!=typeof i)throw new Error("Expected attributes to be an object.");return new e((function(t,e){if("undefined"==typeof window)return t();!function(t){var e=t.url,n=t.attributes,i=t.onSuccess,o=t.onError,s=Y(e,n);s.onerror=o,s.onload=i,document.head.insertBefore(s,document.head.firstElementChild)}({url:n,attributes:i,onSuccess:function(){return t()},onError:function(){var t=new Error('The script "'.concat(n,'" failed to load.'));return window.fetch?fetch(n).then((function(n){return 200===n.status&&e(t),n.text()})).then((function(t){var n=function(t){var e=t.split("/* Original Error:")[1];return e?e.replace(/\n/g,"").replace("*/","").trim():t}(t);e(new Error(n))})).catch((function(t){e(t)})):e(t)}})}))}({url:i,attributes:o},e).then((function(){var t=J(s);if(t)return t;throw new Error("The window.".concat(s," global variable is not available."))}))}function X(){if("undefined"==typeof Promise)throw new Error("Promise is undefined. To resolve the issue, use a Promise polyfill.");return Promise}function J(t){return window[t]}function K(t,e){if("object"!=typeof t||null===t)throw new Error("Expected an options object.");if(void 0!==e&&"function"!=typeof e)throw new Error("Expected PromisePonyfill to be a function.")}class Q extends b{constructor(t,e,n){super("div",Object.assign(Object.assign({},n),{id:"payrails-paypal-button",events:Object.assign(Object.assign({},null==n?void 0:n.events),{onSaveInstrumentCheckboxChanged:async t=>{var e,n,i,o;null===(e=this.button)||void 0===e||e.close(),this.paypalLoader=null,this.paypalLoader=new m(this.loadPaypal.bind(this)),this.button=await this.paypalLoader.loader,this.button.render(`#${this.buttonWrapperId}`),null===(o=null===(i=null===(n=this.options)||void 0===n?void 0:n.events)||void 0===i?void 0:i.onSaveInstrumentCheckboxChanged)||void 0===o||o.call(i,t)}})})),this.sdkConfig=t,this.execution=e,this.options=n,this.paypalLoader=null,this.buttonWrapperId="payrails-paypal-button-wrapper",this.checkboxWrapperId="payrails-paypal-checkbox-wrapper",this.createOneTimeOrder=async()=>{var t,e,n,i,o,s,a;const r=[{paymentMethodCode:"payPal",integrationType:"api",amount:this.sdkConfig.amount,paymentInstrumentData:{providerData:{riskSessionCorrelationId:this.fraudNetGuid}},storeInstrument:!1}],l=await this.paymentExecutor.pay(r),d=null===(n=null===(e=null===(t=l.response.links.confirm)||void 0===t?void 0:t.action)||void 0===e?void 0:e.parameters)||void 0===n?void 0:n.orderId;if(!d)throw null===(s=null===(o=null===(i=this.options)||void 0===i?void 0:i.events)||void 0===o?void 0:o.onAuthorizeFailed)||void 0===s||s.call(o),new Z("No order id returned");return this.confirmLink=null===(a=l.response.links.confirm)||void 0===a?void 0:a.href,d},this.element.innerHTML=`<div id="${this.buttonWrapperId}"></div><div id="${this.checkboxWrapperId}"></div>`,this.paymentExecutor=new p(t,e),this.paypalLoader=new m(this.loadPaypal.bind(this)),this.fraudNetGuid=null==n?void 0:n.fraudNetGuid}async loadPaypal(){const t=this.execution.paypalConfig,e=this.shouldStoreInstrument?"tokenize":"Instant"===this.execution.paypalConfig.captureMode?"capture":"authorize",n=await W({"client-id":t.clientId,components:"buttons,funding-eligibility",intent:e,currency:this.sdkConfig.amount.currency,vault:this.shouldStoreInstrument});if(n){return await this.createPaypalButton(n)}throw new Error("Paypal not available")}async createPaypalButton(t){var e,n,i;if(!t.Buttons)throw new Error("Paypal button not available");const o=await t.Buttons(this.createPayPalButtonConfig());return o.isEligible()?(null===(i=null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onPaypalAvailable)||void 0===i||i.call(n),o):null}createPayPalButtonConfig(){return this.shouldStoreInstrument?this.createBillingAgreementConfig():this.createOneTimeOrderConfig()}createBillingAgreementConfig(){return Object.assign(Object.assign({},this.createBaseConfig()),{onApprove:this.approvePayment.bind(this),createBillingAgreement:async()=>{var t,e,n,i;const o=[{paymentMethodCode:"payPal",integrationType:"api",amount:this.sdkConfig.amount,paymentInstrumentData:{providerData:{riskSessionCorrelationId:this.fraudNetGuid}},storeInstrument:!0}],s=await this.paymentExecutor.pay(o);return this.confirmLink=null===(t=s.response.links.confirm)||void 0===t?void 0:t.href,(null===(i=null===(n=null===(e=s.response.links.confirm)||void 0===e?void 0:e.action)||void 0===n?void 0:n.parameters)||void 0===i?void 0:i.tokenId)||""}})}createOneTimeOrderConfig(){return Object.assign(Object.assign({},this.createBaseConfig()),{createOrder:this.createOneTimeOrder.bind(this),onApprove:this.approvePayment.bind(this)})}createBaseConfig(){var t,e,n,i,o,s,a,r,l,d;return{fundingSource:"paypal",style:{color:(null===(e=null===(t=this.options)||void 0===t?void 0:t.styles)||void 0===e?void 0:e.color)||"gold",height:(null===(i=null===(n=this.options)||void 0===n?void 0:n.styles)||void 0===i?void 0:i.height)||40,label:(null===(s=null===(o=this.options)||void 0===o?void 0:o.styles)||void 0===s?void 0:s.label)||"paypal",shape:(null===(r=null===(a=this.options)||void 0===a?void 0:a.styles)||void 0===r?void 0:r.shape)||"rect",tagline:(null===(d=null===(l=this.options)||void 0===l?void 0:l.styles)||void 0===d?void 0:d.tagline)||!1},onError:t=>{var e,n;(null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onAuthorizeFailed)&&this.options.events.onAuthorizeFailed(t)},onClick:async(t,e)=>{var n,i;if(null===(i=null===(n=this.options)||void 0===n?void 0:n.events)||void 0===i?void 0:i.onPaymentButtonClicked){return await this.options.events.onPaymentButtonClicked()?e.resolve():e.reject()}}}}async approvePayment(t){var e,n,i,o,s,a,r,l,d,u;if(!this.confirmLink)throw null===(i=null===(n=null===(e=this.options)||void 0===e?void 0:e.events)||void 0===n?void 0:n.onAuthorizeFailed)||void 0===i||i.call(n),new Z("No confirm link");const c={};this.shouldStoreInstrument&&t.billingToken&&(c.tokenId=t.billingToken),this.fraudNetGuid&&(c.riskSessionCorrelationId=this.fraudNetGuid);"authorizeSuccessful"===(null===(o=(await this.paymentExecutor.confirm(this.confirmLink,c)).finalState)||void 0===o?void 0:o.code)?null===(r=null===(a=null===(s=this.options)||void 0===s?void 0:s.events)||void 0===a?void 0:a.onAuthorizeSuccess)||void 0===r||r.call(a):null===(u=null===(d=null===(l=this.options)||void 0===l?void 0:l.events)||void 0===d?void 0:d.onAuthorizeFailed)||void 0===u||u.call(d)}mount(t){super.mount(t),(async()=>{var t;this.paypalLoader||(this.paypalLoader=new m(this.loadPaypal.bind(this)));const e=await this.paypalLoader.loader;this.button=e;try{null===(t=this.storeInstrumentCheckbox)||void 0===t||t.mount(`#${this.checkboxWrapperId}`),await(null==e?void 0:e.render(`#${this.buttonWrapperId}`))}catch(t){throw new tt(t.message)}})()}unmount(){var t;null===(t=this.button)||void 0===t||t.close(),this.paypalLoader=null,super.unmount()}}class Z extends Error{constructor(t){super(`PaypalOrderError: ${t}`),this.name="PaypalOrderError"}}class tt extends Error{constructor(t){super(`PaypalButtonError: ${t}`),this.name="PaypalButtonError"}}class et extends M{constructor(t,e,n){var i,o;super("payrails-paypal-button-dropin",(null===(o=null===(i=null==n?void 0:n.translations)||void 0===i?void 0:i.labels)||void 0===o?void 0:o.label)||"PayPal"),this.loadElementId="paypal-dropin-load-element",this.component=new Q(t,e,Object.assign(Object.assign({},n),{events:Object.assign(Object.assign({},null==n?void 0:n.events),{onPaypalAvailable:()=>{this.mountAfterAvailable()}})}))}}class nt extends R{constructor(t,e,n){var i,o,s;const a=t.paymentMethod===B.PAYPAL?`${null===(i=t.data)||void 0===i?void 0:i.email}`:`${null===(o=t.data)||void 0===o?void 0:o.bin}**${null===(s=t.data)||void 0===s?void 0:s.suffix}`;super(`payrails-payment-instrument-${t.id}`,a,{onActivate:()=>{n(t),this.component.setDisabled(!1)}}),this.component=e}}class it extends y{constructor(t,e,n,i,o){var s,a;super("fieldset",{id:"payrails-dropin-component"}),this.collectContainer=t,this.dropinConfig=e,this.execution=n,this.sdkConfig=i,this.returnLinks=o;void 0!==(null===(a=null===(s=this.dropinConfig.paymentMethodsConfiguration)||void 0===s?void 0:s.cards)||void 0===a?void 0:a.showExistingCards)&&console.warn("The `showExistingCards` option is deprecated and will be removed in a future version. Please use `showStoredInstruments` instead.");const r=new Map;this.execution.storedPaymentInstruments.forEach((t=>{var e;if(this.isStoredInstrumentEnabled(t.paymentMethod)){this.cardPaymentButton=this.createCardPaymentButton(null===(e=this.dropinConfig.translations)||void 0===e?void 0:e.cardPaymentButton);const n=new nt(t,this.cardPaymentButton,(t=>{this.cardPaymentButton&&(this.cardPaymentButton.selectedCard=t)}));r.set(n.identifier,n)}})),this.execution.availablePaymentMethods.forEach((({paymentMethodCode:t})=>{var e,n,i,o,s;switch(t){case B.PAYPAL:this.paypal=new et(this.sdkConfig,this.execution,Object.assign(Object.assign({},null===(e=this.dropinConfig.paymentMethodsConfiguration)||void 0===e?void 0:e.payPal),{styles:null===(n=this.dropinConfig.styles)||void 0===n?void 0:n.paypalButton,events:{onAuthorizeSuccess:this.onAuthorizeSuccess.bind(this),onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onSaveInstrumentCheckboxChanged:t=>{this.dropinConfig.events.onSaveInstrumentCheckboxChanged&&this.dropinConfig.events.onSaveInstrumentCheckboxChanged(t)}}})),r.set(this.paypal.identifier,this.paypal);break;case B.CARD:this.creditCard=new D(this.createCardForm(),this.createCardPaymentButton(null===(i=this.dropinConfig.translations)||void 0===i?void 0:i.cardPaymentButton)),r.set(this.creditCard.identifier,this.creditCard);break;case B.GOOGLE_PAY:this.googlePay=new G(this.sdkConfig,this.execution,Object.assign({events:{onAuthorizeSuccess:t=>{var e;if(t)if("authorizeSuccessful"===(null===(e=null==t?void 0:t.finalState)||void 0===e?void 0:e.code))this.onAuthorizeSuccess();else this.onAuthorizeFailed()},onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked},styles:null===(o=this.dropinConfig.styles)||void 0===o?void 0:o.googlePayButton},null===(s=this.dropinConfig.paymentMethodsConfiguration)||void 0===s?void 0:s.googlePay)),r.set(this.googlePay.identifier,this.googlePay);break;case B.APPLE_PAY:this.applePay=new N(this.sdkConfig,this.execution,{events:{onAuthorizeSuccess:t=>{var e;if(t)if("authorizeSuccessful"===(null===(e=null==t?void 0:t.finalState)||void 0===e?void 0:e.code))this.onAuthorizeSuccess();else this.onAuthorizeFailed()},onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked}}),r.set(this.applePay.identifier,this.applePay)}})),this.element.addEventListener("change",(t=>{var e,n;const i=(null===(e=null==t?void 0:t.target)||void 0===e?void 0:e.value)||"";r.forEach((t=>{t.deactivate()})),null===(n=r.get(i))||void 0===n||n.activate()})),this.subElements.push(...Array.from(r.values()))}createCardForm(){var t,e;if(!this.cardForm){const n=null===(t=this.dropinConfig.paymentMethodsConfiguration)||void 0===t?void 0:t.cards,i=Boolean(null==n?void 0:n.showStoreInstrumentCheckbox),o=Boolean(null==n?void 0:n.showCardHolderName),s=Boolean(null==n?void 0:n.alwaysStoreInstrument);this.cardForm=new S(this.collectContainer,{showStoreInstrumentCheckbox:i,showCardHolderName:o,alwaysStoreInstrument:s,translations:null===(e=this.dropinConfig.translations)||void 0===e?void 0:e.cardForm,events:{onFocus:()=>{var t;null===(t=this.creditCard)||void 0===t||t.activate()},onChange:({isValid:t})=>{var e;null===(e=this.cardPaymentButton)||void 0===e||e.setDisabled(!t)},onSaveInstrumentCheckboxChanged:t=>{this.dropinConfig.events.onSaveInstrumentCheckboxChanged&&this.dropinConfig.events.onSaveInstrumentCheckboxChanged(t)}}})}return this.cardPaymentButton&&this.cardPaymentButton.setCardForm(this.cardForm),this.cardForm}createCardPaymentButton(t){return this.cardPaymentButton||(this.cardPaymentButton=new j(this.sdkConfig,this.execution,{translations:t,events:{onAuthorizeSuccess:this.onAuthorizeSuccess.bind(this),onAuthorizeFailed:this.onAuthorizeFailed.bind(this),onPaymentButtonClicked:this.dropinConfig.events.onPaymentButtonClicked,onPaymentSessionExpired:this.dropinConfig.events.onPaymentSessionExpired}},this.returnLinks)),this.cardForm&&this.cardPaymentButton.setCardForm(this.cardForm),this.cardPaymentButton}onAuthorizeSuccess(){var t,e,n,i;this.subElements.forEach((t=>t.unmount())),new z({translations:{label:null===(n=null===(e=null===(t=this.dropinConfig)||void 0===t?void 0:t.translations)||void 0===e?void 0:e.paymentResult)||void 0===n?void 0:n.success}}).mount(this.selector),(null===(i=this.dropinConfig.events)||void 0===i?void 0:i.onAuthorizeSuccess)&&this.dropinConfig.events.onAuthorizeSuccess()}onAuthorizeFailed(){var t,e,n;new F(null===(e=null===(t=this.dropinConfig.translations)||void 0===t?void 0:t.paymentResult)||void 0===e?void 0:e.fail).mount(this.selector),this.dropinConfig.events.onAuthorizeFailed&&(null===(n=this.dropinConfig.events)||void 0===n||n.onAuthorizeFailed())}isStoredInstrumentEnabled(t){var e,n,i,o,s,a;switch(t){case B.CARD:return!1!==(null===(n=null===(e=this.dropinConfig.paymentMethodsConfiguration)||void 0===e?void 0:e.cards)||void 0===n?void 0:n.showStoredInstruments)||!1!==(null===(o=null===(i=this.dropinConfig.paymentMethodsConfiguration)||void 0===i?void 0:i.cards)||void 0===o?void 0:o.showExistingCards);case B.PAYPAL:case B.GOOGLE_PAY:case B.APPLE_PAY:return!1!==(null===(a=null===(s=this.dropinConfig.paymentMethodsConfiguration)||void 0===s?void 0:s[t])||void 0===a?void 0:a.showStoredInstruments);default:return!1}}}const ot={visa:/^4\d*/,mastercard:/^(5[1-5]|222[1-9]|22[3-9]|2[3-6]|27[0-1]|2720)\d*/,amex:/^3[47]\d*/,diners:/^(36|38|30[0-5])\d*/,discover:/^(6011|65|64[4-9]|622)\d*/,jcb:/^35\d*/,hipercard:/^606282\d*/,unionpay:/^62\d*/,maestro:/^(5018|5020|5038|5043|5[6-9]|6020|6304|6703|6759|676[1-3])\d*/};class st{constructor(t,e,n){this.sdkConfig=n,this.containerType="COMPOSABLE",this.cardTableName=e.cardTableName||"cards",this.containerType=e.containerType||"COMPOSABLE",this.__container=t.container(this.containerType,e)}get elementToFieldMap(){return new Map([[exports.ElementType.CARD_NUMBER,"card_number"],[exports.ElementType.CARDHOLDER_NAME,"cardholder_name"],[exports.ElementType.CVV,"security_code"],[exports.ElementType.EXPIRATION_MONTH,"expiry_month"],[exports.ElementType.EXPIRATION_YEAR,"expiry_year"]])}createCollectElement(t){const e={required:!!t.required,enableCardIcon:!1!==t.enableCardIcon},n=this.__container.create(Object.assign(Object.assign({table:this.cardTableName,labelStyles:{},errorTextStyles:{},column:this.elementToFieldMap.get(t.type)},t),{type:t.type===exports.ElementType.CARDHOLDER_NAME?"INPUT_FIELD":t.type}),t.format?Object.assign(Object.assign({},e),{format:t.format}):e);return this.attachCustomEventHandler(n)}mount(t){if("COLLECT"===this.containerType)throw new Error("Collect container cannot be mounted");const e="payrails-container-wrapper";this.element=document.createElement("span"),this.element.setAttribute("id",e);const n=document.querySelector(t);if(!n)throw new Error(`Element with selector ${t} does not exist`);n.appendChild(this.element),window.setTimeout((()=>{this.__container.mount(`#${e}`)}),50)}unmount(){this.element&&this.element.remove()}async collect(){const{records:t}=await this.__container.collect(),{skyflow_id:e,card_number:n,cardholder_name:i,expiry_month:o,expiry_year:s,security_code:a}=t[0].fields;return{instrumentId:e,card_number:n,cardholder_name:i,expiry_month:o,expiry_year:s,security_code:a}}async tokenize(t){const e=await this.collect(),{instrumentId:n,card_number:i,cardholder_name:o,expiry_month:a,expiry_year:r,security_code:d}=e,u=this.sdkConfig.vaultConfiguration.links.saveInstrument.href,c=this.sdkConfig.token,h=this.sdkConfig.holderReference;if(!u)throw new Error("Save instrument URL not available!");const v=await(({url:t,token:e,instrumentId:n,holderReference:i,providerId:o,providerConfigId:a,meta:r,storeInstrument:d=!1,futureUsage:u="CardOnFile"})=>l({url:t,token:e,method:s.POST,body:{holderReference:i,storeInstrument:d,futureUsage:u,paymentMethod:"card",token:{providerId:o,providerConfigId:a,reference:n,type:"vault",meta:r}}}))({url:u,token:c,instrumentId:n,holderReference:h,providerId:this.sdkConfig.vaultConfiguration.providerId,providerConfigId:this.sdkConfig.vaultConfiguration.providerConfigId,meta:{skyflow_id:n,card_number:i,cardholder_name:o,expiry_month:a,expiry_year:r,security_code:d},storeInstrument:t.storeInstrument||!1,futureUsage:t.futureUsage||"CardOnFile"});return v.res}attachCustomEventHandler(t){return new Proxy(t,{get(t,e){if("on"!==e)return t[e];return((n,i)=>{t[e].call(t,n,(t=>{"CHANGE"===n?(t.elementType===exports.ElementType.CARD_NUMBER&&(t.network=function(t){for(const[e,n]of Object.entries(ot))if(n.test(t))return e;return""}(t.value)),i(t)):i(t)}))}).bind(t)}})}}class at{constructor(t,e,n){this.pageId=t,this.sdkConfig=e,this.environment=n,this.guid=r().replace(/-/g,""),this.fnclsVal="fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99",this.configId=r(),this.scriptId=r(),this.execution=new T(e.execution)}mount(){this.loadFraudnet(this.pageId)}unmount(){var t,e;null===(t=document.getElementById(this.configId))||void 0===t||t.remove(),null===(e=document.getElementById(this.scriptId))||void 0===e||e.remove()}loadFraudnet(t){this.unmount();const e=this.createFraudnetConfig(t);document.body.appendChild(e);const n=document.createElement("script");n.setAttribute("id",this.scriptId),n.src="https://c.paypal.com/da/r/fb.js",document.body.appendChild(n)}get payPalConfig(){return this.execution.paypalConfig}createFraudnetConfig(t){const e=document.createElement("script");return e.setAttribute("type","application/json"),e.setAttribute("fncls",this.fnclsVal),e.setAttribute("id",this.configId),e.innerText=JSON.stringify({f:this.guid,s:`${this.payPalConfig.merchantId}_${t}`,sandbox:"TEST"===this.environment}),e}}var rt=require("skyflow-js").default;class lt{static init(t,e){const n=JSON.parse(atob(t.data)),{vaultConfiguration:{vaultId:i,vaultUrl:o,token:s},execution:a}=n,r=rt.init({vaultID:i,vaultURL:o,getBearerToken:()=>Promise.resolve(s)});return new lt(n,r,new T(a),e)}update(t){this.sdkConfiguration.amount=t}collectContainer(t){if("COMPOSABLE"===t.containerType&&!t.layout)throw new Error("Layout configuration is required");return this.__container=new st(this.vaultClient,Object.assign(Object.assign({},t),{cardTableName:this.sdkConfiguration.vaultConfiguration.cardTableName}),this.sdkConfiguration),this.__container}googlePayButton(t){var e;if(!this.execution)throw new Error("SDK was not initialized with workflow execution");return new V(this.sdkConfiguration,this.execution,Object.assign({environment:null===(e=this.options)||void 0===e?void 0:e.environment},t))}applePayButton(t){if(!this.execution)throw new Error("SDK was not initialized with workflow execution");return new f(this.sdkConfiguration,this.execution,t)}cardList(t){return this.__cardList||(this.__cardList=new O(this.execution,{onCardChange:e=>{this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=e,this.__cardPaymentButton.setDisabled(!1)),null==t||t.onCardChange(e)}})),this.__cardList}cardForm(t){var e,n;if(!this.__cardForm){const i=this.getContainerLayout(null==t?void 0:t.showCardHolderName);this.__container=this.collectContainer(Object.assign(Object.assign({layout:i,errorTextStyles:{base:{display:"none"}}},null===(e=null==t?void 0:t.styles)||void 0===e?void 0:e.errorTextStyles),{styles:{base:null===(n=null==t?void 0:t.styles)||void 0===n?void 0:n.base}})),this.__cardForm=new S(this.__container,Object.assign(Object.assign({},t),{events:Object.assign(Object.assign({},null==t?void 0:t.events),{onChange:e=>{var n;this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=null,this.__cardForm&&this.__cardPaymentButton.setDisabled(!this.__cardForm.isValid)),(null===(n=null==t?void 0:t.events)||void 0===n?void 0:n.onChange)&&t.events.onChange(e)},onFocus:()=>{var e;this.__cardList&&this.__cardList.reset(),this.__cardPaymentButton&&(this.__cardPaymentButton.selectedCard=null,this.__cardForm&&this.__cardPaymentButton.setDisabled(!this.__cardForm.isValid)),(null===(e=null==t?void 0:t.events)||void 0===e?void 0:e.onFocus)&&t.events.onFocus()}})}))}return this.__cardPaymentButton&&this.__cardPaymentButton.setCardForm(this.__cardForm),this.__cardForm}dropin(t){var e,n,i;const o=this.getContainerLayout(null===(n=null===(e=t.paymentMethodsConfiguration)||void 0===e?void 0:e.cards)||void 0===n?void 0:n.showCardHolderName);return this.__container=this.collectContainer({layout:o,errorTextStyles:{base:{display:"none"}}}),new it(this.__container,t,this.execution,this.sdkConfiguration,(null===(i=this.options)||void 0===i?void 0:i.returnLinks)||{})}getSavedCreditCards(){return this.execution.savedCreditCards}paymentButton(t){var e;return this.__cardPaymentButton||(this.__cardPaymentButton=new j(this.sdkConfiguration,this.execution,t,(null===(e=this.options)||void 0===e?void 0:e.returnLinks)||{})),this.__cardPaymentButton.setDisabled(!0),this.__cardForm&&this.__cardPaymentButton.setCardForm(this.__cardForm),this.__cardPaymentButton}paypalButton(t){var e;return this.__paypalButton=new Q(this.sdkConfiguration,this.execution,Object.assign(Object.assign({},t),{fraudNetGuid:(null==t?void 0:t.fraudNetGuid)||(null===(e=this.__fraudNet)||void 0===e?void 0:e.guid)})),this.__paypalButton}getSavedPaypalAccounts(){return this.execution.savedPaypalAccounts||[]}fraudNet(t){var e;return this.__fraudNet||(this.__fraudNet=new at(t,this.sdkConfiguration,(null===(e=this.options)||void 0===e?void 0:e.environment)||"TEST")),this.__paypalButton&&(this.__paypalButton.fraudNetGuid=this.__fraudNet.guid),this.__fraudNet}constructor(t,e,n,i){var o;this.sdkConfiguration=t,this.vaultClient=e,this.execution=n,this.options=i,(null===(o=null==i?void 0:i.events)||void 0===o?void 0:o.onClientInitialized)&&i.events.onClientInitialized(this.execution)}getContainerLayout(t){return t?[1,1,3]:[1,3]}}exports.Payrails=lt}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payrails/web-sdk",
3
- "version": "2.6.1",
3
+ "version": "2.7.0-RC",
4
4
  "description": "SDK providing tokenization options on the client for merchants",
5
5
  "main": "index.js",
6
6
  "types": "payrails.d.ts",
package/payrails.d.ts CHANGED
@@ -76,7 +76,7 @@ declare class WorkflowExecution {
76
76
  httpCode: number;
77
77
  body: {
78
78
  data: {
79
- paymentCompositionOptions: (GooglePayCompositionOption | CardCompositionOption)[];
79
+ paymentCompositionOptions: StorablePaymentCompositionOption<CardMetadata | PayPalMetadata, ApplePayConfig | PayPalConfig | GooglePayConfig | undefined>[];
80
80
  };
81
81
  links: {
82
82
  authorize: {
@@ -89,26 +89,12 @@ declare class WorkflowExecution {
89
89
  };
90
90
  } | undefined;
91
91
  get holderReference(): string;
92
- get savedCreditCards(): SavedCreditCard[];
93
- get savedPaypalAccounts(): never[] | SavedPaypalAccount;
94
- get paypalConfig(): {
95
- clientId: string;
96
- merchantId: string;
97
- };
98
- get googlePayConfig(): {
99
- parameters: {
100
- allowedAuthMethods: string[];
101
- allowedCardNetworks: string[];
102
- };
103
- tokenizationSpecification: {
104
- parameters: {
105
- gateway: string;
106
- gatewayMerchantId: string;
107
- };
108
- type: string;
109
- };
110
- type: string;
111
- }[];
92
+ get savedCreditCards(): StoredPaymentInstrument<CardMetadata>[];
93
+ get savedPaypalAccounts(): StoredPaymentInstrument<PayPalMetadata>[];
94
+ get savedGooglePayAccounts(): StoredPaymentInstrument<CardMetadata>[];
95
+ get savedApplePayAccounts(): StoredPaymentInstrument<CardMetadata>[];
96
+ get paypalConfig(): PayPalConfig;
97
+ get googlePayConfig(): GooglePayConfig[];
112
98
  get applePayConfig(): {
113
99
  merchantIdentifier: string;
114
100
  supportedNetworks: string[];
@@ -124,9 +110,11 @@ declare class WorkflowExecution {
124
110
  } | undefined;
125
111
  } | undefined;
126
112
  };
127
- get availablePaymentMethods(): (GooglePayCompositionOption | CardCompositionOption)[];
113
+ get availablePaymentMethods(): StorablePaymentCompositionOption<CardMetadata | PayPalMetadata, ApplePayConfig | PayPalConfig | GooglePayConfig | undefined>[];
128
114
  get authorizeLink(): string | undefined;
129
115
  get createSessionLink(): string;
116
+ get storedPaymentInstruments(): StoredPaymentInstrument<PayPalMetadata & CardMetadata>[];
117
+ private getStoredInstrumentForPaymentMethod;
130
118
  }
131
119
  interface WorkflowExecutionResponse {
132
120
  id: string;
@@ -148,7 +136,7 @@ interface WorkflowExecutionResponse {
148
136
  httpCode: number;
149
137
  body: {
150
138
  data: {
151
- paymentCompositionOptions: Array<GooglePayCompositionOption | CardCompositionOption>;
139
+ paymentCompositionOptions: Array<StorablePaymentCompositionOption>;
152
140
  };
153
141
  links: {
154
142
  authorize: {
@@ -178,47 +166,87 @@ interface WorkflowExecutionResponse {
178
166
  self: string;
179
167
  };
180
168
  }
181
- interface PaymentCompositionOption {
169
+ interface StorablePaymentCompositionOption<I = CardMetadata | PayPalMetadata, C = undefined | ApplePayConfig | PayPalConfig | GooglePayConfig> {
182
170
  paymentMethodCode?: PAYMENT_METHOD_CODES;
183
171
  description: string;
172
+ id: string;
173
+ status: PAYMENT_INSTRUMENT_STATUS;
174
+ config: C;
175
+ paymentInstruments?: Array<StoredPaymentInstrument<I>>;
184
176
  integrationType: string;
185
177
  }
186
- interface CardCompositionOption extends PaymentCompositionOption {
187
- paymentInstruments?: Array<SavedCreditCard>;
188
- }
189
- interface GooglePayCompositionOption extends PaymentCompositionOption {
190
- config: {
178
+ interface GooglePayConfig {
179
+ parameters: {
180
+ allowedAuthMethods: string[];
181
+ allowedCardNetworks: string[];
182
+ };
183
+ tokenizationSpecification: {
191
184
  parameters: {
192
- allowedAuthMethods: string[];
193
- allowedCardNetworks: string[];
194
- };
195
- tokenizationSpecification: {
196
- parameters: {
197
- gateway: string;
198
- gatewayMerchantId: string;
199
- };
200
- type: string;
185
+ gateway: string;
186
+ gatewayMerchantId: string;
201
187
  };
202
188
  type: string;
203
189
  };
190
+ type: string;
204
191
  }
205
- interface SavedCreditCard {
206
- id: string;
207
- status: PAYMENT_INSTRUMENT_STATUS;
208
- data: {
209
- bin: string;
210
- suffix: string;
192
+ interface PayPalConfig {
193
+ clientId: string;
194
+ merchantId: string;
195
+ captureMode: 'Delayed' | 'Instant' | 'Manual';
196
+ }
197
+ interface ApplePayConfig {
198
+ parameters: {
199
+ merchantIdentifier: string;
200
+ supportedNetworks: string[];
201
+ countryCode: string;
202
+ merchantCapabilities: ApplePayJS.ApplePayMerchantCapability[];
211
203
  };
204
+ type: string;
212
205
  }
213
- interface SavedPaypalAccount {
206
+ interface StoredPaymentInstrument<T = CardMetadata | PayPalMetadata> {
214
207
  id: string;
215
208
  status: PAYMENT_INSTRUMENT_STATUS;
216
- data?: {
217
- email?: string;
209
+ paymentMethod: PAYMENT_METHOD_CODES;
210
+ data?: T;
211
+ }
212
+ interface PayPalMetadata {
213
+ email?: string;
214
+ }
215
+ interface CardMetadata {
216
+ bin?: string;
217
+ suffix?: string;
218
+ }
219
+
220
+ interface StoreInstrumentElementOptions extends ElementOptions {
221
+ showStoreInstrumentCheckbox?: boolean;
222
+ alwaysStoreInstrument?: boolean;
223
+ translations?: {
224
+ labels?: {
225
+ storeInstrument?: string;
226
+ saveInstrument?: string;
227
+ };
228
+ };
229
+ styles?: {
230
+ storeInstrumentCheckbox?: Partial<CSSStyleDeclaration>;
218
231
  };
232
+ events?: PayrailsSDKEvents;
233
+ }
234
+ declare class StoreInstrumentCheckbox extends PayrailsElement {
235
+ private options;
236
+ constructor(options: StoreInstrumentElementOptions);
237
+ get isChecked(): boolean;
238
+ private createHTML;
239
+ private applyStyles;
240
+ private addListeners;
241
+ }
242
+ declare abstract class PayrailsElementWithStoreInstrumentCheckbox extends PayrailsElement {
243
+ protected options?: StoreInstrumentElementOptions | undefined;
244
+ protected storeInstrumentCheckbox: StoreInstrumentCheckbox | null;
245
+ protected constructor(elementType: string, options?: StoreInstrumentElementOptions | undefined);
246
+ protected get shouldStoreInstrument(): boolean;
219
247
  }
220
248
 
221
- interface ApplePayButtonOptions {
249
+ interface ApplePayButtonOptions extends StoreInstrumentElementOptions {
222
250
  events?: PaymentEvents & {
223
251
  onApplePayAvailable?: () => void;
224
252
  };
@@ -228,10 +256,10 @@ declare global {
228
256
  ApplePaySession?: ApplePaySession;
229
257
  }
230
258
  }
231
- declare class ApplePayButton extends PayrailsElement {
259
+ declare class ApplePayButton extends PayrailsElementWithStoreInstrumentCheckbox {
232
260
  private sdkConfig;
233
261
  private execution;
234
- private options;
262
+ protected options: ApplePayButtonOptions;
235
263
  private appleButton;
236
264
  private loadScript;
237
265
  private paymentExecutor;
@@ -257,11 +285,6 @@ declare const regexes: {
257
285
  };
258
286
  type CardNetwork = keyof typeof regexes;
259
287
 
260
- interface StoreInstrumentElementOptions {
261
- showStoreInstrumentCheckbox?: boolean;
262
- alwaysStoreInstrument?: boolean;
263
- }
264
-
265
288
  interface OnChange {
266
289
  isValid: boolean;
267
290
  cardNetwork: CardNetwork | '';
@@ -275,6 +298,9 @@ interface CardFormOptions extends StoreInstrumentElementOptions {
275
298
  };
276
299
  labels?: {
277
300
  [key in ElementType | 'saveCreditCard']?: string;
301
+ } & {
302
+ saveInstrument?: string;
303
+ storeInstrument?: string;
278
304
  };
279
305
  };
280
306
  events?: {
@@ -285,6 +311,7 @@ interface CardFormOptions extends StoreInstrumentElementOptions {
285
311
  styles?: {
286
312
  base?: Partial<CSSStyleDeclaration>;
287
313
  storeCardCheckbox?: Partial<CSSStyleDeclaration>;
314
+ storeInstrumentCheckbox?: Partial<CSSStyleDeclaration>;
288
315
  errorTextStyles?: {
289
316
  base: Partial<CSSStyleDeclaration>;
290
317
  };
@@ -296,10 +323,9 @@ interface CardFormOptions extends StoreInstrumentElementOptions {
296
323
  };
297
324
  };
298
325
  }
299
- declare class CardForm extends PayrailsElement {
326
+ declare class CardForm extends PayrailsElementWithStoreInstrumentCheckbox {
300
327
  private readonly collectContainer;
301
- private readonly options?;
302
- private readonly storeCardCheckbox;
328
+ protected readonly options?: CardFormOptions | undefined;
303
329
  private readonly formFields;
304
330
  constructor(collectContainer: PayrailsCollectContainer, options?: CardFormOptions | undefined);
305
331
  show(): void;
@@ -318,7 +344,7 @@ declare class CardForm extends PayrailsElement {
318
344
  expiry_year: string | undefined;
319
345
  security_code: string;
320
346
  };
321
- storeInstrument: boolean | undefined;
347
+ storeInstrument: boolean;
322
348
  enrollInstrumentToNetworkOffers: boolean;
323
349
  }>;
324
350
  }
@@ -335,7 +361,7 @@ interface CardFieldStyles extends LabelStyles {
335
361
  }
336
362
 
337
363
  interface CardListOptions {
338
- onCardChange: (selectedCard: SavedCreditCard) => void;
364
+ onCardChange: (selectedCard: StoredPaymentInstrument<CardMetadata>) => void;
339
365
  }
340
366
  declare class CardList extends PayrailsElement {
341
367
  private readonly workflowExecution;
@@ -344,6 +370,12 @@ declare class CardList extends PayrailsElement {
344
370
  reset(): void;
345
371
  }
346
372
 
373
+ interface RedirectReturnLinks {
374
+ success?: string;
375
+ cancel?: string;
376
+ error?: string;
377
+ }
378
+
347
379
  interface CardPaymentButtonOptions {
348
380
  events?: PayrailsSDKEvents;
349
381
  translations?: {
@@ -360,12 +392,14 @@ declare class CardPaymentButton extends PayrailsElement {
360
392
  private readonly sdkConfig;
361
393
  private readonly execution;
362
394
  private readonly options;
363
- selectedCard: SavedCreditCard | null;
395
+ private readonly returnLinks;
396
+ selectedCard: StoredPaymentInstrument | null;
364
397
  private paymentExecutor;
365
398
  private cardForm;
366
- constructor(sdkConfig: SdkConfiguration, execution: WorkflowExecution, options: CardPaymentButtonOptions);
399
+ constructor(sdkConfig: SdkConfiguration, execution: WorkflowExecution, options: CardPaymentButtonOptions, returnLinks: RedirectReturnLinks);
367
400
  setDisabled(isDisabled: boolean): void;
368
- setSavedCreditCard(savedCard: SavedCreditCard): void;
401
+ setSavedCreditCard(savedCard: StoredPaymentInstrument<CardMetadata>): void;
402
+ setSavedInstrument(savedInstrument: StoredPaymentInstrument): void;
369
403
  private setStyles;
370
404
  private removeStyles;
371
405
  setLabel(label: string): void;
@@ -378,9 +412,9 @@ declare class CardPaymentButton extends PayrailsElement {
378
412
  private collectCardFormValues;
379
413
  }
380
414
 
381
- interface GooglePayButtonOptions {
415
+ interface GooglePayButtonOptions extends StoreInstrumentElementOptions {
382
416
  environment?: 'TEST' | 'PRODUCTION';
383
- events?: PaymentEvents & {
417
+ events?: PaymentEvents & UIEvents & {
384
418
  onGooglePayAvailable?: () => void;
385
419
  };
386
420
  styles?: {
@@ -388,12 +422,13 @@ interface GooglePayButtonOptions {
388
422
  buttonType?: google.payments.api.ButtonType;
389
423
  buttonSizeMode?: google.payments.api.ButtonSizeMode;
390
424
  buttonLocale?: string;
425
+ storeInstrumentCheckbox?: Partial<CSSStyleDeclaration>;
391
426
  };
392
427
  }
393
- declare class GooglePayButton extends PayrailsElement {
428
+ declare class GooglePayButton extends PayrailsElementWithStoreInstrumentCheckbox {
394
429
  private sdkConfig;
395
430
  private execution;
396
- private options;
431
+ protected options: GooglePayButtonOptions;
397
432
  private googleButton;
398
433
  private paymentExecutor;
399
434
  private loadScript;
@@ -407,7 +442,10 @@ declare class GooglePayButton extends PayrailsElement {
407
442
 
408
443
  interface GooglePayDropinOptions extends GooglePayButtonOptions {
409
444
  translations?: {
410
- label?: string;
445
+ labels?: {
446
+ label?: string;
447
+ storeInstrument?: string;
448
+ };
411
449
  };
412
450
  }
413
451
 
@@ -424,26 +462,19 @@ interface PaypalButtonOptions extends StoreInstrumentElementOptions {
424
462
  tagline?: boolean;
425
463
  storeInstrumentCheckbox?: Partial<CSSStyleDeclaration>;
426
464
  };
427
- translations?: {
428
- labels?: {
429
- saveInstrument?: string;
430
- };
431
- };
432
465
  }
433
- declare class PaypalButton extends PayrailsElement {
466
+ declare class PaypalButton extends PayrailsElementWithStoreInstrumentCheckbox {
434
467
  private sdkConfig;
435
468
  private execution;
436
- private options?;
469
+ protected options?: PaypalButtonOptions | undefined;
437
470
  constructor(sdkConfig: SdkConfiguration, execution: WorkflowExecution, options?: PaypalButtonOptions | undefined);
438
471
  fraudNetGuid: string | undefined;
439
472
  private paymentExecutor;
440
473
  private button;
441
474
  private paypalLoader;
442
475
  private confirmLink;
443
- private storeInstrumentCheckbox;
444
476
  private buttonWrapperId;
445
477
  private checkboxWrapperId;
446
- private get isBillingAgreement();
447
478
  private loadPaypal;
448
479
  private createPaypalButton;
449
480
  private createPayPalButtonConfig;
@@ -470,26 +501,32 @@ declare class Dropin extends PayrailsElement {
470
501
  private readonly dropinConfig;
471
502
  private readonly execution;
472
503
  private readonly sdkConfig;
504
+ private readonly returnLinks;
473
505
  private cardPaymentButton;
474
506
  private creditCard;
475
507
  private googlePay;
476
508
  private applePay;
477
509
  private cardForm;
478
510
  private paypal;
479
- constructor(collectContainer: PayrailsCollectContainer, dropinConfig: DropinConfiguration, execution: WorkflowExecution, sdkConfig: SdkConfiguration);
511
+ constructor(collectContainer: PayrailsCollectContainer, dropinConfig: DropinConfiguration, execution: WorkflowExecution, sdkConfig: SdkConfiguration, returnLinks: RedirectReturnLinks);
480
512
  private createCardForm;
481
513
  private createCardPaymentButton;
482
514
  private onAuthorizeSuccess;
483
515
  private onAuthorizeFailed;
516
+ private isStoredInstrumentEnabled;
517
+ }
518
+ interface StorablePaymentMethodConfiguration extends StoreInstrumentElementOptions {
519
+ showStoredInstruments?: boolean;
484
520
  }
485
521
  interface DropinConfiguration {
486
522
  paymentMethodsConfiguration?: {
487
523
  cards?: {
488
524
  showCardHolderName?: boolean;
489
- showStoredInstruments?: boolean;
490
525
  showExistingCards?: boolean;
491
- } & StoreInstrumentElementOptions;
492
- paypal?: StoreInstrumentElementOptions;
526
+ } & StorablePaymentMethodConfiguration;
527
+ payPal?: StorablePaymentMethodConfiguration;
528
+ googlePay?: StorablePaymentMethodConfiguration;
529
+ applePay?: StorablePaymentMethodConfiguration;
493
530
  };
494
531
  returnInfo?: {
495
532
  success: string;
@@ -535,6 +572,7 @@ interface PayrailsClientOptions {
535
572
  events?: {
536
573
  onClientInitialized: (execution: WorkflowExecution) => void;
537
574
  };
575
+ returnLinks?: RedirectReturnLinks;
538
576
  }
539
577
  declare class Payrails {
540
578
  private sdkConfiguration;
@@ -555,10 +593,10 @@ declare class Payrails {
555
593
  cardList(options?: CardListOptions): CardList;
556
594
  cardForm(options?: CardFormOptions): CardForm;
557
595
  dropin(options: DropinConfiguration): Dropin;
558
- getSavedCreditCards(): SavedCreditCard[];
596
+ getSavedCreditCards(): StoredPaymentInstrument<CardMetadata>[];
559
597
  paymentButton(options: CardPaymentButtonOptions): CardPaymentButton;
560
598
  paypalButton(options?: PaypalButtonOptions): PaypalButton;
561
- getSavedPaypalAccounts(): never[] | SavedPaypalAccount;
599
+ getSavedPaypalAccounts(): StoredPaymentInstrument<PayPalMetadata>[];
562
600
  fraudNet(pageId: FraudNetPageId): FraudNet;
563
601
  private constructor();
564
602
  private getContainerLayout;