@moneyhash/js-sdk
Advanced tools
Comparing version 1.11.1 to 1.11.2-beta.0
@@ -1,1 +0,1 @@ | ||
"use strict";var we=Object.defineProperty,Pe=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var G=(o,e,t)=>e in o?we(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,P=(o,e)=>{for(var t in e||(e={}))re.call(e,t)&&G(o,t,e[t]);if(q)for(var t of q(e))ie.call(e,t)&&G(o,t,e[t]);return o},_=(o,e)=>Pe(o,be(e));var se=(o,e)=>{var t={};for(var r in o)re.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&q)for(var r of q(o))e.indexOf(r)<0&&ie.call(o,r)&&(t[r]=o[r]);return t};var f=(o,e,t)=>(G(o,typeof e!="symbol"?e+"":e,t),t),ke=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var b=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)};var y=(o,e,t)=>(ke(o,e,"access private method"),t);var h=(o,e,t)=>new Promise((r,a)=>{var i=n=>{try{s(t.next(n))}catch(l){a(l)}},d=n=>{try{s(t.throw(n))}catch(l){a(l)}},s=n=>n.done?r(n.value):Promise.resolve(n.value).then(i,d);s((t=t.apply(o,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("./warnIf-47ecdac8.cjs");function Ae(){return typeof window!="undefined"}const k=class{constructor(){Ae()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=c.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.11.1");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),k.messagingService=new c.MessagingService({target:r.contentWindow,targetOrigin:e}),k.isCommunicationReady=new Promise(a=>{var d;const i=s=>{var n;s.data.type==="headlessSDK:init"&&(a(),(n=k.messagingService)==null||n.removeListener(i))};(d=k.messagingService)==null||d.onReceive(i)})}request(r){return h(this,arguments,function*({api:e,payload:t}){return yield k.isCommunicationReady,new Promise((a,i)=>{var s,n;(s=k.messagingService)==null||s.send({type:e,data:t});const d=l=>{var g;const{type:p,data:u}=l.data;p===e&&(u.status==="resolved"?a(u.payload):i(u.payload),(g=k.messagingService)==null||g.removeListener(d))};(n=k.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=k.messagingService)==null||t.send({type:e})}};let C=k;f(C,"messagingService",null),f(C,"isCommunicationReady");class F{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Ee(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function v(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function oe(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function de(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function le(o){if(typeof o!="object"||o===null)return!1;const e=Object.getPrototypeOf(o);return e===Object.prototype||e===null}function B(o,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const i=document.createElement("script");i.src=o,i.id=e,i.addEventListener("load",()=>{t(void 0)}),i.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(i)})}function Ie(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const ce=new Set(["method","customerBalance","savedCard"]);var M,K,R,Y,H,pe,$,ue,N,he,L,x,V,me,D,ge,j,ye,O,fe;class Se{constructor(e){b(this,M);b(this,R);b(this,H);b(this,$);b(this,N);b(this,L);b(this,V);b(this,D);b(this,j);b(this,O);f(this,"options");f(this,"sdkApiHandler",new C);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>h(this,null,function*(){c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=oe(this.mountedCardElements);c.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,R,Y).call(this,{accessToken:t})}),pay:s=>h(this,[s],function*({intentId:e,cardData:t,saveCard:r,billingData:a,shippingData:i,installmentPlanData:d}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:i,cardEmbed:t,saveCard:r,installmentPlanData:d}})}),createCardToken:r=>h(this,[r],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new c.SDKEmbed(_(P({},e),{headless:!0})),y(this,D,ge).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),c.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:P({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:r,useWalletBalance:a,metaData:i,installmentPlanData:d}){return c.throwIf(!ce.has(t),`type must be a valid one (${[...ce].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData:i,installmentPlanData:d}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return c.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(l){return h(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:a,onCancel:i=()=>{},onError:d,onComplete:s,billingData:n=!0}){if(yield B("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const p=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`},requiredShippingContactFields:n===!0?["email"]:void 0}),{state:u,intent:g}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(u==="FORM_FIELDS"){if(!le(n)||de(n))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:n}})}}catch(A){throw yield this.resetSelectedMethod(e),A}const w=new F;return p.onvalidatemerchant=A=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:g.secret,validationUrl:A.validationURL,parentOrigin:window.location.origin}}).then(I=>p.completeMerchantValidation(I)).catch(d),p.onpaymentauthorized=A=>{var I;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:A.payment.token}),receiptBillingData:{email:(I=A.payment.shippingContact)==null?void 0:I.emailAddress}}}).then(U=>{p.completePayment(ApplePaySession.STATUS_SUCCESS),s==null||s(),w.resolve(U)}).catch(()=>{p.completePayment(ApplePaySession.STATUS_FAILURE),d==null||d(),w.reject(void 0)})},p.oncancel=i,p.begin(),w.promise})}renderGooglePayButton(r){return h(this,null,function*(){var a=r,{onClick:e}=a,t=se(a,["onClick"]);var s;const i=document.getElementById("moneyHash-google-pay-button");c.throwIf(!i,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield B("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((s=this.options.googlePay)==null?void 0:s.environment)||"PRODUCTION"});const d=y(this,M,K).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const l=this.googlePaymentsClient.createButton(_(P({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:d.allowedPaymentMethods,onClick:e}));i==null||i.replaceChildren(l)}else throw new Error("Google Pay is not ready to pay!")}).catch(n=>{console.dir(n)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t,billingData:r=!0}){return c.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),c.throwIf(!e,"nativePayData is required to generate Google Pay receipt!"),c.throwIf(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(_(P({},y(this,M,K).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:r})).then(a=>({receipt:a.paymentMethodData.tokenizationData.token,receiptBillingData:{email:a.email}})).catch(a=>(a.statusCode==="CANCELED"?t==null||t():console.dir(a),Promise.reject(a)))}generateApplePayReceipt(a){return h(this,arguments,function*({nativePayData:e,onCancel:t=()=>{},billingData:r=!0}){if(yield B("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),c.throwIf(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(c.throwIf(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const i=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:r?["email"]:void 0}),d=new F;return i.onvalidatemerchant=s=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:s.validationURL,parentOrigin:window.location.origin}}).then(n=>i.completeMerchantValidation(n)).catch(n=>{i.abort(),d.reject(n)}),i.onpaymentauthorized=s=>{var l;const n={receipt:JSON.stringify({token:s.payment.token}),receiptBillingData:{email:(l=s.payment.shippingContact)==null?void 0:l.emailAddress}};i.completePayment(ApplePaySession.STATUS_SUCCESS),d.resolve(n)},i.oncancel=t,i.begin(),d.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(a){return h(this,arguments,function*({intentId:e,billingData:t=!0,onCancel:r}){c.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let i=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(i.state==="FORM_FIELDS"){if(!le(t)||de(t))throw new Error("Billing data is missing while calling payWithGooglePay");i=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(s){throw yield this.resetSelectedMethod(e),s}const{nativePayData:d}=i;return d?this.generateGooglePayReceipt({nativePayData:d,onCancel:r,billingData:typeof t=="boolean"?t:!1}).then(s=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:s})):i})}renderForm(e){return c.throwIf(!e.selector,"selector is required for renderForm"),c.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){c.warnIf(!!e&&!c.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...c.supportedLanguages].join(" | ")})`);const t=c.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return c.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(r=>{c.throwIf(!r.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:r}){const a=[],i={},d=new Map;let s=!1;return y(this,V,me).call(this,a),{create:({elementType:n,elementOptions:l})=>{var I,U;const p=new Map;let u=null;const g=P(P({},t),l.classes),w=((I=g==null?void 0:g.focus)==null?void 0:I.split(" "))||["MoneyHashElement--focus"],A=((U=g==null?void 0:g.error)==null?void 0:U.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const m=document.querySelector(l.selector);c.throwIf(!m,`Couldn't find an element with selector ${l.selector}!`),m.classList.add("MoneyHashElement"),a.push(T=>{var z,J,X,Q,Z,ee,te,ae,ne;const{type:E,data:S}=T.data;if(E===`${n}@mount`&&(i[n]=S.isValid,(z=p.get(`${n}@mount`))==null||z()),E===`${n}@focus`){m.classList.add(...w),(J=p.get(`${n}@focus`))==null||J();return}if(E===`${n}@blur`){m.classList.remove(...w),(X=p.get(`${n}@blur`))==null||X();return}if(E===`${n}@error`){S.isValid?m.classList.remove(...A):m.classList.add(...A),(Q=p.get(`${n}@error`))==null||Q(S);return}if(E===`${n}@changeInput`){if((Z=p.get(`${n}@changeInput`))==null||Z({isValid:S.isValid,length:S.length}),i[n]=S.isValid,d.get("validityChange")){const W=Object.values(i).every(Boolean);W!==s&&((ee=d.get("validityChange"))==null||ee(W),s=W)}return}if(E===`${n}@cardNumberChange`){(te=p.get(`${n}@cardNumberChange`))==null||te(S);return}if(E===`${n}@key:Backspace`){(ae=p.get(`${n}@key:Backspace`))==null||ae();return}E===`${n}@key:Enter`&&((ne=p.get(`${n}@key:Enter`))==null||ne())}),u=y(this,j,ye).call(this,{container:m,elementType:n,elementOptions:l,styles:P(P({},e),l.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(m,T)=>{p.set(`${n}@${m}`,T)},off:m=>p.delete(`${n}@${m}`),focus:()=>{var m;(m=u==null?void 0:u.contentWindow)==null||m.postMessage({type:"focus"},v())},blur:()=>{var m;(m=u==null?void 0:u.contentWindow)==null||m.postMessage({type:"blur"},v())},clear:()=>{var m;(m=u==null?void 0:u.contentWindow)==null||m.postMessage({type:"clear"},v())}}},on:(n,l)=>{d.set(n,l)}}}submitForm(n){return h(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:a,saveCard:i,paymentMethod:d="CARD",installmentPlanData:s}){let l;if(t){const u=oe(this.mountedCardElements);c.throwIf(!!u,`You must mount ${u} element!`),l=yield y(this,R,Y).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:d,lang:this.sdkEmbed.lang,billingData:r,shippingData:a,cardEmbed:l,saveCard:i,installmentPlanData:s}})})}selectInstallmentPlan(a){return h(this,arguments,function*({intentId:e,planId:t,issuerCode:r}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:r,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(a){return h(this,arguments,function*({first6Digits:e,amount:t,currency:r}){return c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:r,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(a){return h(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:r}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:r,lang:this.sdkEmbed.lang}})})}renderUrl(i){return h(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),r){case"IFRAME":return y(this,H,pe).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,$,ue).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,N,he).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const r=new Date(e),a=setInterval(()=>h(this,null,function*(){const i=new Date;r<i&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}M=new WeakSet,K=function(e){var r,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[P({type:"CARD",parameters:{allowedAuthMethods:((r=this.options.googlePay)==null?void 0:r.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((a=this.options.googlePay)==null?void 0:a.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},R=new WeakSet,Y=function(t){return h(this,arguments,function*({accessToken:e}){const r=new F;this.vaultSubmitListener.current=d=>{const{type:s,data:n}=d.data;s==="vaultSubmit:success"&&r.resolve(n),s==="vaultSubmit:error"&&r.reject(n)};const a=y(this,O,fe).call(this,{accessToken:e}),i=yield r.promise;return a.remove(),i})},H=new WeakSet,pe=function(r){return h(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");c.throwIf(!a,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const i=document.createElement("iframe");i.src=t,i.style.setProperty("border","0","important"),i.style.setProperty("width","100%","important"),i.style.setProperty("height","100%","important"),a==null||a.replaceChildren(i),yield y(this,L,x).call(this,{intentId:e}),i.remove()})},$=new WeakSet,ue=function(a){return h(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:i=600,height:d=400,left:s=200,top:n=200}=r.window||{},l=window.open(t,"",`width=${i},height=${d},left=${s},top=${n}`);c.throwIf(!l,"Popup blocked by browser!"),yield y(this,L,x).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},N=new WeakSet,he=function(r){return h(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},L=new WeakSet,x=function(r){return h(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new F,i=d=>h(this,null,function*(){var n,l,p,u;if(d.origin!==c.getIframeUrl())return;const{type:s}=d.data;if(s==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[g]=yield Promise.all([this.getIntentDetails(e),Ie(2)]),w=g.transaction.status.split(".")[1];w==="successful"||w.startsWith("pending")?(l=(n=this.options).onComplete)==null||l.call(n,P({type:this.options.type},g)):(u=(p=this.options).onFail)==null||u.call(p,P({type:this.options.type},g)),a.resolve(()=>null),window.removeEventListener("message",i)}});return window.addEventListener("message",i),a.promise})},V=new WeakSet,me=function(e){const t=r=>{r.origin===v()&&e.forEach(a=>{a(r)})};window.addEventListener("message",t)},D=new WeakSet,ge=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},j=new WeakSet,ye=function({container:e,elementType:t,elementOptions:r,styles:a,fontSourceCss:i}){var l,p,u,g,w;const d=v(),s=new URL(`${d}/vaultField/vaultField.html`);i&&s.searchParams.set("fontSourceCss",i),s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("type",t),((l=r.validation)==null?void 0:l.required)!==void 0&&s.searchParams.set("required",`${(p=r.validation)==null?void 0:p.required}`),s.searchParams.set("placeholder",(u=r.placeholder)!=null?u:""),s.searchParams.set("inputMode",(g=r.inputMode)!=null?g:""),s.searchParams.set("lang",this.sdkEmbed.lang),s.searchParams.set("direction",(a==null?void 0:a.direction)||""),s.searchParams.set("color",JSON.stringify(a!=null&&a.color?a.color:"#000")),s.searchParams.set("placeholderColor",(a==null?void 0:a.placeholderColor)||"#ccc"),s.searchParams.set("backgroundColor",(a==null?void 0:a.backgroundColor)||"transparent"),s.searchParams.set("fontSize",(a==null?void 0:a.fontSize)||""),s.searchParams.set("fontFamily",(a==null?void 0:a.fontFamily)||""),s.searchParams.set("fontWeight",`${a==null?void 0:a.fontWeight}`),s.searchParams.set("fontStyle",(a==null?void 0:a.fontStyle)||""),s.searchParams.set("padding",(a==null?void 0:a.padding)||"");const n=document.createElement("iframe");return n.src=s.toString(),n.style.height=(w=a==null?void 0:a.height)!=null?w:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n),n},O=new WeakSet,fe=function({accessToken:e}){const t=v(),r=Ee(),a=new URL(`${t}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang);const i=document.createElement("iframe");return i.id="moneyhash-submit-iframe",i.src=a.toString(),i.hidden=!0,document.body.appendChild(i),i};exports.IFrameSandboxOptions=c.IFrameSandboxOptions;exports.default=Se; | ||
"use strict";var Ee=Object.defineProperty,Ie=Object.defineProperties;var Se=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var Y=(o,e,t)=>e in o?Ee(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,b=(o,e)=>{for(var t in e||(e={}))de.call(e,t)&&Y(o,t,e[t]);if(_)for(var t of _(e))le.call(e,t)&&Y(o,t,e[t]);return o},F=(o,e)=>Ie(o,Se(e));var ce=(o,e)=>{var t={};for(var i in o)de.call(o,i)&&e.indexOf(i)<0&&(t[i]=o[i]);if(o!=null&&_)for(var i of _(o))e.indexOf(i)<0&&le.call(o,i)&&(t[i]=o[i]);return t};var w=(o,e,t)=>(Y(o,typeof e!="symbol"?e+"":e,t),t),pe=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var H=(o,e,t)=>(pe(o,e,"read from private field"),t?t.call(o):e.get(o)),f=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)};var y=(o,e,t)=>(pe(o,e,"access private method"),t);var h=(o,e,t)=>new Promise((i,a)=>{var r=n=>{try{s(t.next(n))}catch(c){a(c)}},d=n=>{try{s(t.throw(n))}catch(c){a(c)}},s=n=>n.done?i(n.value):Promise.resolve(n.value).then(r,d);s((t=t.apply(o,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("./warnIf-0c917262.cjs");function ve(){return typeof window!="undefined"}const k=class{constructor(){ve()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=l.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.11.2-beta.0");const i=document.createElement("iframe");i.id="moneyhash-headless-sdk",i.src=t.toString(),i.hidden=!0,document.body.appendChild(i),k.messagingService=new l.MessagingService({target:i.contentWindow,targetOrigin:e}),k.isCommunicationReady=new Promise(a=>{var d;const r=s=>{var n;s.data.type==="headlessSDK:init"&&(a(),(n=k.messagingService)==null||n.removeListener(r))};(d=k.messagingService)==null||d.onReceive(r)})}request(i){return h(this,arguments,function*({api:e,payload:t}){return yield k.isCommunicationReady,new Promise((a,r)=>{var s,n;(s=k.messagingService)==null||s.send({type:e,data:t});const d=c=>{var g;const{type:p,data:u}=c.data;p===e&&(u.status==="resolved"?a(u.payload):r(u.payload),(g=k.messagingService)==null||g.removeListener(d))};(n=k.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=k.messagingService)==null||t.send({type:e})}};let C=k;w(C,"messagingService",null),w(C,"isCommunicationReady");class ${constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Ce(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function v(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function ue(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function he(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function x(o,e){return new Promise((t,i)=>{if(document.getElementById(e)){t(void 0);return}const r=document.createElement("script");r.src=o,r.id=e,r.addEventListener("load",()=>{t(void 0)}),r.addEventListener("error",()=>{i(new Error("Script failed to load"))}),document.body.appendChild(r)})}function Me(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const me=new Set(["method","customerBalance","savedCard"]);var M,z,D,ge,R,J,L,X,N,ye,V,we,B,fe,U,Q,T,Pe,W,be,G,ke,j,Ae;class Re{constructor(e){f(this,M);f(this,D);f(this,R);f(this,L);f(this,N);f(this,V);f(this,B);f(this,U);f(this,T);f(this,W);f(this,G);f(this,j);w(this,"options");w(this,"sdkApiHandler",new C);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);w(this,"googlePaymentsClient",null);w(this,"cardForm",{collect:()=>h(this,null,function*(){l.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=ue(this.mountedCardElements);l.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,L,X).call(this,{accessToken:t})}),pay:s=>h(this,[s],function*({intentId:e,cardData:t,saveCard:i,billingData:a,shippingData:r,installmentPlanData:d}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:r,cardEmbed:t,saveCard:i,installmentPlanData:d}})}),createCardToken:i=>h(this,[i],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new l.SDKEmbed(F(b({},e),{headless:!0})),y(this,W,be).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(l.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),l.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:b({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:i,useWalletBalance:a,metaData:r,installmentPlanData:d}){return l.throwIf(!me.has(t),`type must be a valid one (${[...me].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:i,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData:r,installmentPlanData:d}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return l.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return h(this,arguments,function*({intentId:e,currency:t,amount:i,countryCode:a,onCancel:r=()=>{},onError:d,onComplete:s,billingData:n={}}){if(yield x("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const p=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${i}`},requiredShippingContactFields:H(this,R,J)}),{state:u,intent:g}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(u==="FORM_FIELDS"){if(he(n))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:n}})}}catch(A){throw yield this.resetSelectedMethod(e),A}const P=new $;return p.onvalidatemerchant=A=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:g.secret,validationUrl:A.validationURL,parentOrigin:window.location.origin}}).then(I=>p.completeMerchantValidation(I)).catch(d),p.onpaymentauthorized=A=>{var I;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:A.payment.token}),receiptBillingData:{email:(I=A.payment.shippingContact)==null?void 0:I.emailAddress}}}).then(q=>{p.completePayment(ApplePaySession.STATUS_SUCCESS),s==null||s(),P.resolve(q)}).catch(()=>{p.completePayment(ApplePaySession.STATUS_FAILURE),d==null||d(),P.reject(void 0)})},p.oncancel=r,p.begin(),P.promise})}renderGooglePayButton(i){return h(this,null,function*(){var a=i,{onClick:e}=a,t=ce(a,["onClick"]);var s;const r=document.getElementById("moneyHash-google-pay-button");l.throwIf(!r,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield x("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((s=this.options.googlePay)==null?void 0:s.environment)||"PRODUCTION"});const d=y(this,M,z).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const c=this.googlePaymentsClient.createButton(F(b({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:d.allowedPaymentMethods,onClick:e}));r==null||r.replaceChildren(c)}else throw new Error("Google Pay is not ready to pay!")}).catch(n=>{console.dir(n)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t}){return l.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),l.throwIf(!e,"nativePayData is required to generate Google Pay receipt!"),l.throwIf(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(F(b({},y(this,M,z).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:H(this,D,ge).includes("email")})).then(i=>({receipt:i.paymentMethodData.tokenizationData.token,receiptBillingData:{email:i.email}})).catch(i=>(i.statusCode==="CANCELED"?t==null||t():console.dir(i),Promise.reject(i)))}generateApplePayReceipt(i){return h(this,arguments,function*({nativePayData:e,onCancel:t=()=>{}}){if(yield x("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),l.throwIf(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(l.throwIf(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const a=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:H(this,R,J)}),r=new $;return a.onvalidatemerchant=d=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:d.validationURL,parentOrigin:window.location.origin}}).then(s=>a.completeMerchantValidation(s)).catch(s=>{a.abort(),r.reject(s)}),a.onpaymentauthorized=d=>{var n;const s={receipt:JSON.stringify({token:d.payment.token}),receiptBillingData:{email:(n=d.payment.shippingContact)==null?void 0:n.emailAddress}};a.completePayment(ApplePaySession.STATUS_SUCCESS),r.resolve(s)},a.oncancel=t,a.begin(),r.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(a){return h(this,arguments,function*({intentId:e,billingData:t={},onCancel:i}){l.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let r=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(r.state==="FORM_FIELDS"){if(he(t))throw new Error("Billing data is missing while calling payWithGooglePay");r=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(s){throw yield this.resetSelectedMethod(e),s}const{nativePayData:d}=r;return d?this.generateGooglePayReceipt({nativePayData:d,onCancel:i}).then(s=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:s})):r})}renderForm(e){return l.throwIf(!e.selector,"selector is required for renderForm"),l.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){l.warnIf(!!e&&!l.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...l.supportedLanguages].join(" | ")})`);const t=l.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return l.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(i=>{l.throwIf(!i.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:i}){const a=[],r={},d=new Map;let s=!1;return y(this,T,Pe).call(this,a),{create:({elementType:n,elementOptions:c})=>{var I,q;const p=new Map;let u=null;const g=b(b({},t),c.classes),P=((I=g==null?void 0:g.focus)==null?void 0:I.split(" "))||["MoneyHashElement--focus"],A=((q=g==null?void 0:g.error)==null?void 0:q.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const m=document.querySelector(c.selector);l.throwIf(!m,`Couldn't find an element with selector ${c.selector}!`),m.classList.add("MoneyHashElement"),a.push(O=>{var Z,ee,te,ae,ie,ne,re,se,oe;const{type:E,data:S}=O.data;if(E===`${n}@mount`&&(r[n]=S.isValid,(Z=p.get(`${n}@mount`))==null||Z()),E===`${n}@focus`){m.classList.add(...P),(ee=p.get(`${n}@focus`))==null||ee();return}if(E===`${n}@blur`){m.classList.remove(...P),(te=p.get(`${n}@blur`))==null||te();return}if(E===`${n}@error`){S.isValid?m.classList.remove(...A):m.classList.add(...A),(ae=p.get(`${n}@error`))==null||ae(S);return}if(E===`${n}@changeInput`){if((ie=p.get(`${n}@changeInput`))==null||ie({isValid:S.isValid,length:S.length}),r[n]=S.isValid,d.get("validityChange")){const K=Object.values(r).every(Boolean);K!==s&&((ne=d.get("validityChange"))==null||ne(K),s=K)}return}if(E===`${n}@cardNumberChange`){(re=p.get(`${n}@cardNumberChange`))==null||re(S);return}if(E===`${n}@key:Backspace`){(se=p.get(`${n}@key:Backspace`))==null||se();return}E===`${n}@key:Enter`&&((oe=p.get(`${n}@key:Enter`))==null||oe())}),u=y(this,G,ke).call(this,{container:m,elementType:n,elementOptions:c,styles:b(b({},e),c.styles),fontSourceCss:i}),this.mountedCardElements.push(n)},on:(m,O)=>{p.set(`${n}@${m}`,O)},off:m=>p.delete(`${n}@${m}`),focus:()=>{var m;(m=u==null?void 0:u.contentWindow)==null||m.postMessage({type:"focus"},v())},blur:()=>{var m;(m=u==null?void 0:u.contentWindow)==null||m.postMessage({type:"blur"},v())},clear:()=>{var m;(m=u==null?void 0:u.contentWindow)==null||m.postMessage({type:"clear"},v())}}},on:(n,c)=>{d.set(n,c)}}}submitForm(n){return h(this,arguments,function*({intentId:e,accessToken:t,billingData:i,shippingData:a,saveCard:r,paymentMethod:d="CARD",installmentPlanData:s}){let c;if(t){const u=ue(this.mountedCardElements);l.throwIf(!!u,`You must mount ${u} element!`),c=yield y(this,L,X).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:d,lang:this.sdkEmbed.lang,billingData:i,shippingData:a,cardEmbed:c,saveCard:r,installmentPlanData:s}})})}selectInstallmentPlan(a){return h(this,arguments,function*({intentId:e,planId:t,issuerCode:i}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:i,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(a){return h(this,arguments,function*({first6Digits:e,amount:t,currency:i}){return l.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:i,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(a){return h(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:i}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:i,lang:this.sdkEmbed.lang}})})}renderUrl(r){return h(this,arguments,function*({intentId:e,url:t,renderStrategy:i,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),i){case"IFRAME":return y(this,N,ye).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,V,we).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,B,fe).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const i=new Date(e),a=setInterval(()=>h(this,null,function*(){const r=new Date;i<r&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}M=new WeakSet,z=function(e){var i,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[b({type:"CARD",parameters:{allowedAuthMethods:((i=this.options.googlePay)==null?void 0:i.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((a=this.options.googlePay)==null?void 0:a.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},D=new WeakSet,ge=function(){var e;return((e=this.options.googlePay)==null?void 0:e.collectibleBillingData)||["email"]},R=new WeakSet,J=function(){var e;return((e=this.options.applePay)==null?void 0:e.collectibleBillingData)||["email"]},L=new WeakSet,X=function(t){return h(this,arguments,function*({accessToken:e}){const i=new $;this.vaultSubmitListener.current=d=>{const{type:s,data:n}=d.data;s==="vaultSubmit:success"&&i.resolve(n),s==="vaultSubmit:error"&&i.reject(n)};const a=y(this,j,Ae).call(this,{accessToken:e}),r=yield i.promise;return a.remove(),r})},N=new WeakSet,ye=function(i){return h(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");l.throwIf(!a,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const r=document.createElement("iframe");r.src=t,r.style.setProperty("border","0","important"),r.style.setProperty("width","100%","important"),r.style.setProperty("height","100%","important"),a==null||a.replaceChildren(r),yield y(this,U,Q).call(this,{intentId:e}),r.remove()})},V=new WeakSet,we=function(a){return h(this,arguments,function*({intentId:e,url:t,options:i={}}){const{width:r=600,height:d=400,left:s=200,top:n=200}=i.window||{},c=window.open(t,"",`width=${r},height=${d},left=${s},top=${n}`);l.throwIf(!c,"Popup blocked by browser!"),yield y(this,U,Q).call(this,{intentId:e,isUsingPopUp:!0}),c==null||c.close()})},B=new WeakSet,fe=function(i){return h(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},U=new WeakSet,Q=function(i){return h(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new $,r=d=>h(this,null,function*(){var n,c,p,u;if(d.origin!==l.getIframeUrl())return;const{type:s}=d.data;if(s==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[g]=yield Promise.all([this.getIntentDetails(e),Me(2)]),P=g.transaction.status.split(".")[1];P==="successful"||P.startsWith("pending")?(c=(n=this.options).onComplete)==null||c.call(n,b({type:this.options.type},g)):(u=(p=this.options).onFail)==null||u.call(p,b({type:this.options.type},g)),a.resolve(()=>null),window.removeEventListener("message",r)}});return window.addEventListener("message",r),a.promise})},T=new WeakSet,Pe=function(e){const t=i=>{i.origin===v()&&e.forEach(a=>{a(i)})};window.addEventListener("message",t)},W=new WeakSet,be=function(e){const t=i=>{e.current&&e.current(i)};window.addEventListener("message",t)},G=new WeakSet,ke=function({container:e,elementType:t,elementOptions:i,styles:a,fontSourceCss:r}){var c,p,u,g,P;const d=v(),s=new URL(`${d}/vaultField/vaultField.html`);r&&s.searchParams.set("fontSourceCss",r),s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("type",t),((c=i.validation)==null?void 0:c.required)!==void 0&&s.searchParams.set("required",`${(p=i.validation)==null?void 0:p.required}`),s.searchParams.set("placeholder",(u=i.placeholder)!=null?u:""),s.searchParams.set("inputMode",(g=i.inputMode)!=null?g:""),s.searchParams.set("lang",this.sdkEmbed.lang),s.searchParams.set("direction",(a==null?void 0:a.direction)||""),s.searchParams.set("color",JSON.stringify(a!=null&&a.color?a.color:"#000")),s.searchParams.set("placeholderColor",(a==null?void 0:a.placeholderColor)||"#ccc"),s.searchParams.set("backgroundColor",(a==null?void 0:a.backgroundColor)||"transparent"),s.searchParams.set("fontSize",(a==null?void 0:a.fontSize)||""),s.searchParams.set("fontFamily",(a==null?void 0:a.fontFamily)||""),s.searchParams.set("fontWeight",`${a==null?void 0:a.fontWeight}`),s.searchParams.set("fontStyle",(a==null?void 0:a.fontStyle)||""),s.searchParams.set("padding",(a==null?void 0:a.padding)||"");const n=document.createElement("iframe");return n.src=s.toString(),n.style.height=(P=a==null?void 0:a.height)!=null?P:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n),n},j=new WeakSet,Ae=function({accessToken:e}){const t=v(),i=Ce(),a=new URL(`${t}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang);const r=document.createElement("iframe");return r.id="moneyhash-submit-iframe",r.src=a.toString(),r.hidden=!0,document.body.appendChild(r),r};exports.IFrameSandboxOptions=l.IFrameSandboxOptions;exports.default=Re; |
@@ -615,3 +615,3 @@ export declare interface AbstractIntent { | ||
onComplete?: () => void; | ||
billingData?: boolean | Record<string, unknown>; | ||
billingData?: Record<string, unknown>; | ||
}): Promise<IntentDetails<TType>>; | ||
@@ -647,3 +647,3 @@ /** | ||
* @param onCancel - Callback to be called when user cancels the payment sheet | ||
* @param billingData - Flag to enable/disable auto billing data collection | ||
* @param enableEmailAbstraction - Flag to enable/disable auto billing data collection | ||
* @default billingData true | ||
@@ -654,6 +654,5 @@ * | ||
*/ | ||
generateGooglePayReceipt({ nativePayData, onCancel, billingData, }: { | ||
generateGooglePayReceipt({ nativePayData, onCancel, }: { | ||
nativePayData: Record<string, any> | null; | ||
onCancel?: () => void; | ||
billingData?: boolean; | ||
}): Promise<{ | ||
@@ -672,6 +671,5 @@ receipt: string; | ||
*/ | ||
generateApplePayReceipt({ nativePayData, onCancel, billingData, }: { | ||
generateApplePayReceipt({ nativePayData, onCancel, }: { | ||
nativePayData: Record<string, any> | null; | ||
onCancel?: () => void; | ||
billingData?: boolean; | ||
}): Promise<{ | ||
@@ -713,3 +711,3 @@ receipt: string; | ||
intentId: string; | ||
billingData?: Record<string, unknown> | boolean; | ||
billingData?: Record<string, unknown>; | ||
onCancel?: () => void; | ||
@@ -935,5 +933,17 @@ }): Promise<IntentDetails<TType>>; | ||
allowedCardNetworks?: GoogleAllowedCardNetworks; | ||
/** | ||
* @default ['email'] | ||
*/ | ||
collectibleBillingData?: NativeCollectibleBillingData[]; | ||
}; | ||
applePay: { | ||
/** | ||
* @default ['email'] | ||
*/ | ||
collectibleBillingData?: NativeCollectibleBillingData[]; | ||
}; | ||
} | ||
export declare type NativeCollectibleBillingData = "email"; | ||
export declare type OnCompleteEventOptions<TType extends IntentType> = TType extends "payment" ? PaymentIntentEventOptions : PayoutIntentEventOptions; | ||
@@ -940,0 +950,0 @@ |
@@ -1,27 +0,27 @@ | ||
var be = Object.defineProperty, ke = Object.defineProperties; | ||
var Ae = Object.getOwnPropertyDescriptors; | ||
var q = Object.getOwnPropertySymbols; | ||
var se = Object.prototype.hasOwnProperty, re = Object.prototype.propertyIsEnumerable; | ||
var O = (o, e, t) => e in o ? be(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, P = (o, e) => { | ||
var ve = Object.defineProperty, Ce = Object.defineProperties; | ||
var Me = Object.getOwnPropertyDescriptors; | ||
var _ = Object.getOwnPropertySymbols; | ||
var le = Object.prototype.hasOwnProperty, ce = Object.prototype.propertyIsEnumerable; | ||
var Y = (o, e, t) => e in o ? ve(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, b = (o, e) => { | ||
for (var t in e || (e = {})) | ||
se.call(e, t) && O(o, t, e[t]); | ||
if (q) | ||
for (var t of q(e)) | ||
re.call(e, t) && O(o, t, e[t]); | ||
le.call(e, t) && Y(o, t, e[t]); | ||
if (_) | ||
for (var t of _(e)) | ||
ce.call(e, t) && Y(o, t, e[t]); | ||
return o; | ||
}, _ = (o, e) => ke(o, Ae(e)); | ||
var oe = (o, e) => { | ||
}, F = (o, e) => Ce(o, Me(e)); | ||
var pe = (o, e) => { | ||
var t = {}; | ||
for (var i in o) | ||
se.call(o, i) && e.indexOf(i) < 0 && (t[i] = o[i]); | ||
if (o != null && q) | ||
for (var i of q(o)) | ||
e.indexOf(i) < 0 && re.call(o, i) && (t[i] = o[i]); | ||
le.call(o, i) && e.indexOf(i) < 0 && (t[i] = o[i]); | ||
if (o != null && _) | ||
for (var i of _(o)) | ||
e.indexOf(i) < 0 && ce.call(o, i) && (t[i] = o[i]); | ||
return t; | ||
}; | ||
var f = (o, e, t) => (O(o, typeof e != "symbol" ? e + "" : e, t), t), Ee = (o, e, t) => { | ||
var w = (o, e, t) => (Y(o, typeof e != "symbol" ? e + "" : e, t), t), ue = (o, e, t) => { | ||
if (!e.has(o)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var b = (o, e, t) => { | ||
var H = (o, e, t) => (ue(o, e, "read from private field"), t ? t.call(o) : e.get(o)), P = (o, e, t) => { | ||
if (e.has(o)) | ||
@@ -31,3 +31,3 @@ throw TypeError("Cannot add the same private member more than once"); | ||
}; | ||
var y = (o, e, t) => (Ee(o, e, "access private method"), t); | ||
var y = (o, e, t) => (ue(o, e, "access private method"), t); | ||
var m = (o, e, t) => new Promise((i, a) => { | ||
@@ -49,5 +49,5 @@ var s = (n) => { | ||
}); | ||
import { M as Se, g as ue, S as ve, t as u, w as Ce, s as B } from "./warnIf-7be59aa6.js"; | ||
import { I as $e } from "./warnIf-7be59aa6.js"; | ||
function Me() { | ||
import { M as Re, g as ye, S as Ie, t as u, w as Le, s as x } from "./warnIf-0eba27c6.js"; | ||
import { I as Be } from "./warnIf-0eba27c6.js"; | ||
function Ue() { | ||
return typeof window != "undefined"; | ||
@@ -57,3 +57,3 @@ } | ||
constructor() { | ||
Me() && this.initSDKCommunicationIframe(); | ||
Ue() && this.initSDKCommunicationIframe(); | ||
} | ||
@@ -63,6 +63,6 @@ initSDKCommunicationIframe() { | ||
return; | ||
const e = ue(), t = new URL(`${e}/embed/headless-sdk`); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.11.1"); | ||
const e = ye(), t = new URL(`${e}/embed/headless-sdk`); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.11.2-beta.0"); | ||
const i = document.createElement("iframe"); | ||
i.id = "moneyhash-headless-sdk", i.src = t.toString(), i.hidden = !0, document.body.appendChild(i), k.messagingService = new Se({ | ||
i.id = "moneyhash-headless-sdk", i.src = t.toString(), i.hidden = !0, document.body.appendChild(i), k.messagingService = new Re({ | ||
target: i.contentWindow, | ||
@@ -105,8 +105,8 @@ targetOrigin: e | ||
let M = k; | ||
f(M, "messagingService", null), f(M, "isCommunicationReady"); | ||
class F { | ||
w(M, "messagingService", null), w(M, "isCommunicationReady"); | ||
class $ { | ||
constructor() { | ||
f(this, "promise"); | ||
f(this, "resolve"); | ||
f(this, "reject"); | ||
w(this, "promise"); | ||
w(this, "resolve"); | ||
w(this, "reject"); | ||
this.promise = new Promise((e, t) => { | ||
@@ -117,3 +117,3 @@ this.resolve = e, this.reject = t; | ||
} | ||
function Re() { | ||
function qe() { | ||
var e; | ||
@@ -126,3 +126,3 @@ return (e = window.MONEYHASH_VAULT_API_URL) != null ? e : "https://vault.moneyhash.io"; | ||
} | ||
function de(o) { | ||
function me(o) { | ||
const e = [ | ||
@@ -139,12 +139,6 @@ "cardNumber", | ||
} | ||
function le(o) { | ||
function he(o) { | ||
return (Array.isArray(o) ? o.length : Object.keys(o).length) === 0; | ||
} | ||
function ce(o) { | ||
if (typeof o != "object" || o === null) | ||
return !1; | ||
const e = Object.getPrototypeOf(o); | ||
return e === Object.prototype || e === null; | ||
} | ||
function K(o, e) { | ||
function z(o, e) { | ||
return new Promise((t, i) => { | ||
@@ -163,3 +157,3 @@ if (document.getElementById(e)) { | ||
} | ||
function Ie(o) { | ||
function _e(o) { | ||
return new Promise((e) => { | ||
@@ -171,3 +165,3 @@ setTimeout(() => { | ||
} | ||
const pe = /* @__PURE__ */ new Set([ | ||
const ge = /* @__PURE__ */ new Set([ | ||
"method", | ||
@@ -177,24 +171,26 @@ "customerBalance", | ||
]); | ||
var R, Y, I, x, H, me, $, he, N, ge, L, z, V, ye, D, fe, W, we, j, Pe; | ||
class _e { | ||
var R, J, D, we, I, X, L, Q, N, Pe, V, fe, B, be, U, Z, W, ke, G, Ae, T, Ee, j, Se; | ||
class De { | ||
constructor(e) { | ||
b(this, R); | ||
b(this, I); | ||
b(this, H); | ||
b(this, $); | ||
b(this, N); | ||
b(this, L); | ||
b(this, V); | ||
b(this, D); | ||
b(this, W); | ||
b(this, j); | ||
f(this, "options"); | ||
f(this, "sdkApiHandler", new M()); | ||
f(this, "sdkEmbed"); | ||
f(this, "vaultSubmitListener", { | ||
P(this, R); | ||
P(this, D); | ||
P(this, I); | ||
P(this, L); | ||
P(this, N); | ||
P(this, V); | ||
P(this, B); | ||
P(this, U); | ||
P(this, W); | ||
P(this, G); | ||
P(this, T); | ||
P(this, j); | ||
w(this, "options"); | ||
w(this, "sdkApiHandler", new M()); | ||
w(this, "sdkEmbed"); | ||
w(this, "vaultSubmitListener", { | ||
current: null | ||
}); | ||
f(this, "mountedCardElements", []); | ||
f(this, "googlePaymentsClient", null); | ||
f(this, "cardForm", { | ||
w(this, "mountedCardElements", []); | ||
w(this, "googlePaymentsClient", null); | ||
w(this, "cardForm", { | ||
collect: () => m(this, null, function* () { | ||
@@ -205,3 +201,3 @@ u( | ||
); | ||
const e = de( | ||
const e = me( | ||
this.mountedCardElements | ||
@@ -219,3 +215,3 @@ ); | ||
}); | ||
return y(this, I, x).call(this, { accessToken: t }); | ||
return y(this, L, Q).call(this, { accessToken: t }); | ||
}), | ||
@@ -259,3 +255,3 @@ pay: (r) => m(this, [r], function* ({ | ||
}); | ||
this.options = e, this.sdkEmbed = new ve(_(P({}, e), { headless: !0 })), y(this, D, fe).call(this, this.vaultSubmitListener); | ||
this.options = e, this.sdkEmbed = new Ie(F(b({}, e), { headless: !0 })), y(this, G, Ae).call(this, this.vaultSubmitListener); | ||
} | ||
@@ -309,3 +305,3 @@ /** | ||
api: "sdk:getMethods", | ||
payload: P({ | ||
payload: b({ | ||
intentType: this.options.type, | ||
@@ -375,4 +371,4 @@ lang: this.sdkEmbed.lang, | ||
return u( | ||
!pe.has(t), | ||
`type must be a valid one (${[...pe].join( | ||
!ge.has(t), | ||
`type must be a valid one (${[...ge].join( | ||
" | " | ||
@@ -491,5 +487,5 @@ )})` | ||
onComplete: r, | ||
billingData: n = !0 | ||
billingData: n = {} | ||
}) { | ||
if (yield K( | ||
if (yield z( | ||
"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js", | ||
@@ -509,3 +505,3 @@ "moneyHash-apple-pay-sdk" | ||
}, | ||
requiredShippingContactFields: n === !0 ? ["email"] : void 0 | ||
requiredShippingContactFields: H(this, I, X) | ||
}), { state: p, intent: g } = yield this.proceedWith({ | ||
@@ -518,3 +514,3 @@ intentId: e, | ||
if (p === "FORM_FIELDS") { | ||
if (!ce(n) || le(n)) | ||
if (he(n)) | ||
throw new Error( | ||
@@ -536,3 +532,3 @@ "Billing data is missing while calling payWithApplePay" | ||
} | ||
const w = new F(); | ||
const f = new $(); | ||
return c.onvalidatemerchant = (A) => this.sdkApiHandler.request({ | ||
@@ -559,8 +555,8 @@ api: "sdk:applePaySession", | ||
} | ||
}).then((U) => { | ||
c.completePayment(ApplePaySession.STATUS_SUCCESS), r == null || r(), w.resolve(U); | ||
}).then((q) => { | ||
c.completePayment(ApplePaySession.STATUS_SUCCESS), r == null || r(), f.resolve(q); | ||
}).catch(() => { | ||
c.completePayment(ApplePaySession.STATUS_FAILURE), d == null || d(), w.reject(void 0); | ||
c.completePayment(ApplePaySession.STATUS_FAILURE), d == null || d(), f.reject(void 0); | ||
}); | ||
}, c.oncancel = s, c.begin(), w.promise; | ||
}, c.oncancel = s, c.begin(), f.promise; | ||
}); | ||
@@ -595,3 +591,3 @@ } | ||
onClick: e | ||
} = a, t = oe(a, [ | ||
} = a, t = pe(a, [ | ||
"onClick" | ||
@@ -604,3 +600,3 @@ ]); | ||
"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!" | ||
), yield K( | ||
), yield z( | ||
"https://pay.google.com/gp/p/js/pay.js", | ||
@@ -611,6 +607,6 @@ "moneyHash-google-pay-sdk" | ||
}); | ||
const d = y(this, R, Y).call(this); | ||
const d = y(this, R, J).call(this); | ||
this.googlePaymentsClient.isReadyToPay(d).then((n) => { | ||
if (n.result) { | ||
const l = this.googlePaymentsClient.createButton(_(P({ | ||
const l = this.googlePaymentsClient.createButton(F(b({ | ||
buttonSizeMode: "fill", | ||
@@ -633,3 +629,3 @@ buttonType: "pay" | ||
* @param onCancel - Callback to be called when user cancels the payment sheet | ||
* @param billingData - Flag to enable/disable auto billing data collection | ||
* @param enableEmailAbstraction - Flag to enable/disable auto billing data collection | ||
* @default billingData true | ||
@@ -642,4 +638,3 @@ * | ||
nativePayData: e, | ||
onCancel: t, | ||
billingData: i = !0 | ||
onCancel: t | ||
}) { | ||
@@ -655,3 +650,3 @@ return u( | ||
"nativePayData.amount is required to generate Google Pay receipt!" | ||
), this.googlePaymentsClient.loadPaymentData(_(P({}, y(this, R, Y).call(this, e)), { | ||
), this.googlePaymentsClient.loadPaymentData(F(b({}, y(this, R, J).call(this, e)), { | ||
transactionInfo: { | ||
@@ -668,9 +663,9 @@ totalPriceStatus: "FINAL", | ||
}, | ||
emailRequired: i | ||
})).then((a) => ({ | ||
receipt: a.paymentMethodData.tokenizationData.token, | ||
emailRequired: H(this, D, we).includes("email") | ||
})).then((i) => ({ | ||
receipt: i.paymentMethodData.tokenizationData.token, | ||
receiptBillingData: { | ||
email: a.email | ||
email: i.email | ||
} | ||
})).catch((a) => (a.statusCode === "CANCELED" ? t == null || t() : console.dir(a), Promise.reject(a))); | ||
})).catch((i) => (i.statusCode === "CANCELED" ? t == null || t() : console.dir(i), Promise.reject(i))); | ||
} | ||
@@ -686,10 +681,9 @@ /** | ||
*/ | ||
generateApplePayReceipt(a) { | ||
generateApplePayReceipt(i) { | ||
return m(this, arguments, function* ({ | ||
nativePayData: e, | ||
onCancel: t = () => { | ||
}, | ||
billingData: i = !0 | ||
} | ||
}) { | ||
if (yield K( | ||
if (yield z( | ||
"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js", | ||
@@ -707,3 +701,3 @@ "moneyHash-apple-pay-sdk" | ||
throw new Error("Apple Pay is not supported!"); | ||
const s = new ApplePaySession(3, { | ||
const a = new ApplePaySession(3, { | ||
countryCode: e.country_code, | ||
@@ -718,25 +712,25 @@ currencyCode: e.currency_code, | ||
}, | ||
requiredShippingContactFields: i ? ["email"] : void 0 | ||
}), d = new F(); | ||
return s.onvalidatemerchant = (r) => this.sdkApiHandler.request({ | ||
requiredShippingContactFields: H(this, I, X) | ||
}), s = new $(); | ||
return a.onvalidatemerchant = (d) => this.sdkApiHandler.request({ | ||
api: "sdk:applePaySession", | ||
payload: { | ||
methodId: e.method_id, | ||
validationUrl: r.validationURL, | ||
validationUrl: d.validationURL, | ||
parentOrigin: window.location.origin | ||
} | ||
}).then( | ||
(n) => s.completeMerchantValidation(n) | ||
).catch((n) => { | ||
s.abort(), d.reject(n); | ||
}), s.onpaymentauthorized = (r) => { | ||
var l; | ||
const n = { | ||
receipt: JSON.stringify({ token: r.payment.token }), | ||
(r) => a.completeMerchantValidation(r) | ||
).catch((r) => { | ||
a.abort(), s.reject(r); | ||
}), a.onpaymentauthorized = (d) => { | ||
var n; | ||
const r = { | ||
receipt: JSON.stringify({ token: d.payment.token }), | ||
receiptBillingData: { | ||
email: (l = r.payment.shippingContact) == null ? void 0 : l.emailAddress | ||
email: (n = d.payment.shippingContact) == null ? void 0 : n.emailAddress | ||
} | ||
}; | ||
s.completePayment(ApplePaySession.STATUS_SUCCESS), d.resolve(n); | ||
}, s.oncancel = t, s.begin(), d.promise; | ||
a.completePayment(ApplePaySession.STATUS_SUCCESS), s.resolve(r); | ||
}, a.oncancel = t, a.begin(), s.promise; | ||
}); | ||
@@ -784,3 +778,3 @@ } | ||
intentId: e, | ||
billingData: t = !0, | ||
billingData: t = {}, | ||
onCancel: i | ||
@@ -799,3 +793,3 @@ }) { | ||
if (s.state === "FORM_FIELDS") { | ||
if (!ce(t) || le(t)) | ||
if (he(t)) | ||
throw new Error( | ||
@@ -820,4 +814,3 @@ "Billing data is missing while calling payWithGooglePay" | ||
nativePayData: d, | ||
onCancel: i, | ||
billingData: typeof t == "boolean" ? t : !1 | ||
onCancel: i | ||
}).then( | ||
@@ -864,9 +857,9 @@ (r) => this.submitPaymentReceipt({ | ||
setLocale(e) { | ||
Ce( | ||
!!e && !B.has(e), | ||
`Invalid locale. Supported languages (${[...B].join( | ||
Le( | ||
!!e && !x.has(e), | ||
`Invalid locale. Supported languages (${[...x].join( | ||
" | " | ||
)})` | ||
); | ||
const t = B.has(e) ? e : "en"; | ||
const t = x.has(e) ? e : "en"; | ||
return this.sdkEmbed.setLocale(t); | ||
@@ -951,3 +944,3 @@ } | ||
let r = !1; | ||
return y(this, V, ye).call(this, a), { | ||
return y(this, W, ke).call(this, a), { | ||
/** | ||
@@ -975,8 +968,8 @@ * Creates card field element | ||
create: ({ elementType: n, elementOptions: l }) => { | ||
var S, U; | ||
var S, q; | ||
const c = /* @__PURE__ */ new Map(); | ||
let p = null; | ||
const g = P(P({}, t), l.classes), w = ((S = g == null ? void 0 : g.focus) == null ? void 0 : S.split(" ")) || [ | ||
const g = b(b({}, t), l.classes), f = ((S = g == null ? void 0 : g.focus) == null ? void 0 : S.split(" ")) || [ | ||
"MoneyHashElement--focus" | ||
], A = ((U = g == null ? void 0 : g.error) == null ? void 0 : U.split(" ")) || [ | ||
], A = ((q = g == null ? void 0 : g.error) == null ? void 0 : q.split(" ")) || [ | ||
"MoneyHashElement--error" | ||
@@ -992,26 +985,26 @@ ]; | ||
`Couldn't find an element with selector ${l.selector}!` | ||
), h.classList.add("MoneyHashElement"), a.push((G) => { | ||
var J, X, Q, Z, ee, te, ae, ne, ie; | ||
const { type: E, data: v } = G.data; | ||
if (E === `${n}@mount` && (s[n] = v.isValid, (J = c.get(`${n}@mount`)) == null || J()), E === `${n}@focus`) { | ||
h.classList.add(...w), (X = c.get(`${n}@focus`)) == null || X(); | ||
), h.classList.add("MoneyHashElement"), a.push((O) => { | ||
var ee, te, ae, ie, ne, se, re, oe, de; | ||
const { type: E, data: v } = O.data; | ||
if (E === `${n}@mount` && (s[n] = v.isValid, (ee = c.get(`${n}@mount`)) == null || ee()), E === `${n}@focus`) { | ||
h.classList.add(...f), (te = c.get(`${n}@focus`)) == null || te(); | ||
return; | ||
} | ||
if (E === `${n}@blur`) { | ||
h.classList.remove(...w), (Q = c.get(`${n}@blur`)) == null || Q(); | ||
h.classList.remove(...f), (ae = c.get(`${n}@blur`)) == null || ae(); | ||
return; | ||
} | ||
if (E === `${n}@error`) { | ||
v.isValid ? h.classList.remove(...A) : h.classList.add(...A), (Z = c.get(`${n}@error`)) == null || Z(v); | ||
v.isValid ? h.classList.remove(...A) : h.classList.add(...A), (ie = c.get(`${n}@error`)) == null || ie(v); | ||
return; | ||
} | ||
if (E === `${n}@changeInput`) { | ||
if ((ee = c.get(`${n}@changeInput`)) == null || ee({ | ||
if ((ne = c.get(`${n}@changeInput`)) == null || ne({ | ||
isValid: v.isValid, | ||
length: v.length | ||
}), s[n] = v.isValid, d.get("validityChange")) { | ||
const T = Object.values(s).every(Boolean); | ||
T !== r && ((te = d.get("validityChange")) == null || te( | ||
T | ||
), r = T); | ||
const K = Object.values(s).every(Boolean); | ||
K !== r && ((se = d.get("validityChange")) == null || se( | ||
K | ||
), r = K); | ||
} | ||
@@ -1021,3 +1014,3 @@ return; | ||
if (E === `${n}@cardNumberChange`) { | ||
(ae = c.get(`${n}@cardNumberChange`)) == null || ae( | ||
(re = c.get(`${n}@cardNumberChange`)) == null || re( | ||
v | ||
@@ -1028,16 +1021,16 @@ ); | ||
if (E === `${n}@key:Backspace`) { | ||
(ne = c.get(`${n}@key:Backspace`)) == null || ne(); | ||
(oe = c.get(`${n}@key:Backspace`)) == null || oe(); | ||
return; | ||
} | ||
E === `${n}@key:Enter` && ((ie = c.get(`${n}@key:Enter`)) == null || ie()); | ||
}), p = y(this, W, we).call(this, { | ||
E === `${n}@key:Enter` && ((de = c.get(`${n}@key:Enter`)) == null || de()); | ||
}), p = y(this, T, Ee).call(this, { | ||
container: h, | ||
elementType: n, | ||
elementOptions: l, | ||
styles: P(P({}, e), l.styles), | ||
styles: b(b({}, e), l.styles), | ||
fontSourceCss: i | ||
}), this.mountedCardElements.push(n); | ||
}, | ||
on: (h, G) => { | ||
c.set(`${n}@${h}`, G); | ||
on: (h, O) => { | ||
c.set(`${n}@${h}`, O); | ||
}, | ||
@@ -1099,3 +1092,3 @@ off: (h) => c.delete(`${n}@${h}`), | ||
if (t) { | ||
const p = de( | ||
const p = me( | ||
this.mountedCardElements | ||
@@ -1106,3 +1099,3 @@ ); | ||
`You must mount ${p} element!` | ||
), l = yield y(this, I, x).call(this, { | ||
), l = yield y(this, L, Q).call(this, { | ||
accessToken: t | ||
@@ -1225,7 +1218,7 @@ }); | ||
case "IFRAME": | ||
return y(this, H, me).call(this, { url: t, intentId: e }); | ||
return y(this, N, Pe).call(this, { url: t, intentId: e }); | ||
case "POPUP_IFRAME": | ||
return y(this, $, he).call(this, { url: t, intentId: e, options: a }); | ||
return y(this, V, fe).call(this, { url: t, intentId: e, options: a }); | ||
case "REDIRECT": | ||
return y(this, N, ge).call(this, { url: t, options: a }); | ||
return y(this, B, be).call(this, { url: t, options: a }); | ||
default: | ||
@@ -1258,3 +1251,3 @@ return null; | ||
} | ||
R = new WeakSet(), Y = function(e) { | ||
R = new WeakSet(), J = function(e) { | ||
var i, a; | ||
@@ -1265,3 +1258,3 @@ return { | ||
allowedPaymentMethods: [ | ||
P({ | ||
b({ | ||
type: "CARD", | ||
@@ -1292,5 +1285,11 @@ parameters: { | ||
}; | ||
}, I = new WeakSet(), x = function(t) { | ||
}, D = new WeakSet(), we = function() { | ||
var e; | ||
return ((e = this.options.googlePay) == null ? void 0 : e.collectibleBillingData) || ["email"]; | ||
}, I = new WeakSet(), X = function() { | ||
var e; | ||
return ((e = this.options.applePay) == null ? void 0 : e.collectibleBillingData) || ["email"]; | ||
}, L = new WeakSet(), Q = function(t) { | ||
return m(this, arguments, function* ({ accessToken: e }) { | ||
const i = new F(); | ||
const i = new $(); | ||
this.vaultSubmitListener.current = (d) => { | ||
@@ -1300,3 +1299,3 @@ const { type: r, data: n } = d.data; | ||
}; | ||
const a = y(this, j, Pe).call(this, { | ||
const a = y(this, j, Se).call(this, { | ||
accessToken: e | ||
@@ -1306,3 +1305,3 @@ }), s = yield i.promise; | ||
}); | ||
}, H = new WeakSet(), me = function(i) { | ||
}, N = new WeakSet(), Pe = function(i) { | ||
return m(this, arguments, function* ({ | ||
@@ -1318,5 +1317,5 @@ intentId: e, | ||
const s = document.createElement("iframe"); | ||
s.src = t, s.style.setProperty("border", "0", "important"), s.style.setProperty("width", "100%", "important"), s.style.setProperty("height", "100%", "important"), a == null || a.replaceChildren(s), yield y(this, L, z).call(this, { intentId: e }), s.remove(); | ||
s.src = t, s.style.setProperty("border", "0", "important"), s.style.setProperty("width", "100%", "important"), s.style.setProperty("height", "100%", "important"), a == null || a.replaceChildren(s), yield y(this, U, Z).call(this, { intentId: e }), s.remove(); | ||
}); | ||
}, $ = new WeakSet(), he = function(a) { | ||
}, V = new WeakSet(), fe = function(a) { | ||
return m(this, arguments, function* ({ | ||
@@ -1337,5 +1336,5 @@ intentId: e, | ||
); | ||
u(!l, "Popup blocked by browser!"), yield y(this, L, z).call(this, { intentId: e, isUsingPopUp: !0 }), l == null || l.close(); | ||
u(!l, "Popup blocked by browser!"), yield y(this, U, Z).call(this, { intentId: e, isUsingPopUp: !0 }), l == null || l.close(); | ||
}); | ||
}, N = new WeakSet(), ge = function(i) { | ||
}, B = new WeakSet(), be = function(i) { | ||
return m(this, arguments, function* ({ | ||
@@ -1351,3 +1350,3 @@ url: e, | ||
}); | ||
}, L = new WeakSet(), z = function(i) { | ||
}, U = new WeakSet(), Z = function(i) { | ||
return m(this, arguments, function* ({ | ||
@@ -1357,5 +1356,5 @@ intentId: e, | ||
}) { | ||
const a = new F(), s = (d) => m(this, null, function* () { | ||
const a = new $(), s = (d) => m(this, null, function* () { | ||
var n, l, c, p; | ||
if (d.origin !== ue()) | ||
if (d.origin !== ye()) | ||
return; | ||
@@ -1367,7 +1366,7 @@ const { type: r } = d.data; | ||
this.getIntentDetails(e), | ||
Ie(2) | ||
]), w = g.transaction.status.split(".")[1]; | ||
w === "successful" || w.startsWith("pending") ? (l = (n = this.options).onComplete) == null || l.call(n, P({ | ||
_e(2) | ||
]), f = g.transaction.status.split(".")[1]; | ||
f === "successful" || f.startsWith("pending") ? (l = (n = this.options).onComplete) == null || l.call(n, b({ | ||
type: this.options.type | ||
}, g)) : (p = (c = this.options).onFail) == null || p.call(c, P({ | ||
}, g)) : (p = (c = this.options).onFail) == null || p.call(c, b({ | ||
type: this.options.type | ||
@@ -1379,3 +1378,3 @@ }, g)), a.resolve(() => null), window.removeEventListener("message", s); | ||
}); | ||
}, V = new WeakSet(), ye = function(e) { | ||
}, W = new WeakSet(), ke = function(e) { | ||
const t = (i) => { | ||
@@ -1387,3 +1386,3 @@ i.origin === C() && e.forEach((a) => { | ||
window.addEventListener("message", t); | ||
}, D = new WeakSet(), fe = function(e) { | ||
}, G = new WeakSet(), Ae = function(e) { | ||
const t = (i) => { | ||
@@ -1393,3 +1392,3 @@ e.current && e.current(i); | ||
window.addEventListener("message", t); | ||
}, W = new WeakSet(), we = function({ | ||
}, T = new WeakSet(), Ee = function({ | ||
container: e, | ||
@@ -1401,3 +1400,3 @@ elementType: t, | ||
}) { | ||
var l, c, p, g, w; | ||
var l, c, p, g, f; | ||
const d = C(), r = new URL(`${d}/vaultField/vaultField.html`); | ||
@@ -1418,5 +1417,5 @@ s && r.searchParams.set("fontSourceCss", s), r.searchParams.set("host", btoa(window.location.origin)), r.searchParams.set("type", t), ((l = i.validation) == null ? void 0 : l.required) !== void 0 && r.searchParams.set( | ||
const n = document.createElement("iframe"); | ||
return n.src = r.toString(), n.style.height = (w = a == null ? void 0 : a.height) != null ? w : "40px", n.style.setProperty("overflow", "hidden", "important"), n.style.setProperty("display", "block", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("maxWidth", "100%", "important"), n.style.setProperty("border", "0", "important"), n.style.setProperty("margin", "0", "important"), n.style.setProperty("padding", "0", "important"), n.style.setProperty("userSelect", "none", "important"), n.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(n), n; | ||
}, j = new WeakSet(), Pe = function({ accessToken: e }) { | ||
const t = C(), i = Re(), a = new URL( | ||
return n.src = r.toString(), n.style.height = (f = a == null ? void 0 : a.height) != null ? f : "40px", n.style.setProperty("overflow", "hidden", "important"), n.style.setProperty("display", "block", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("maxWidth", "100%", "important"), n.style.setProperty("border", "0", "important"), n.style.setProperty("margin", "0", "important"), n.style.setProperty("padding", "0", "important"), n.style.setProperty("userSelect", "none", "important"), n.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(n), n; | ||
}, j = new WeakSet(), Se = function({ accessToken: e }) { | ||
const t = C(), i = qe(), a = new URL( | ||
`${t}/vaultSubmit/vaultSubmit.html` | ||
@@ -1429,4 +1428,4 @@ ); | ||
export { | ||
$e as IFrameSandboxOptions, | ||
_e as default | ||
Be as IFrameSandboxOptions, | ||
De as default | ||
}; |
@@ -1,1 +0,1 @@ | ||
(function(d,l){typeof exports=="object"&&typeof module!="undefined"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(d=typeof globalThis!="undefined"?globalThis:d||self,l(d.MoneyHash={}))})(this,function(d){var N,ee,O,te,D,be,B,Pe,W,ke,V,ie,G,Ae,K,ve,Y,Ee,x,Se;"use strict";var Le=Object.defineProperty,Ue=Object.defineProperties;var _e=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var Z=(d,l,c)=>l in d?Le(d,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[l]=c,A=(d,l)=>{for(var c in l||(l={}))ye.call(l,c)&&Z(d,c,l[c]);if(z)for(var c of z(l))fe.call(l,c)&&Z(d,c,l[c]);return d},J=(d,l)=>Ue(d,_e(l));var we=(d,l)=>{var c={};for(var E in d)ye.call(d,E)&&l.indexOf(E)<0&&(c[E]=d[E]);if(d!=null&&z)for(var E of z(d))l.indexOf(E)<0&&fe.call(d,E)&&(c[E]=d[E]);return c};var b=(d,l,c)=>(Z(d,typeof l!="symbol"?l+"":l,c),c),qe=(d,l,c)=>{if(!l.has(d))throw TypeError("Cannot "+c)};var M=(d,l,c)=>{if(l.has(d))throw TypeError("Cannot add the same private member more than once");l instanceof WeakSet?l.add(d):l.set(d,c)};var v=(d,l,c)=>(qe(d,l,"access private method"),c);var w=(d,l,c)=>new Promise((E,I)=>{var j=C=>{try{q(c.next(C))}catch(H){I(H)}},m=C=>{try{q(c.throw(C))}catch(H){I(H)}},q=C=>C.done?E(C.value):Promise.resolve(C.value).then(j,m);q((c=c.apply(d,l)).next())});class l{constructor(e){b(this,"target");b(this,"targetOrigin");b(this,"listeners");b(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function c(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function E(){return typeof window!="undefined"}const R=class{constructor(){E()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=c(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.11.1");const a=document.createElement("iframe");a.id="moneyhash-headless-sdk",a.src=t.toString(),a.hidden=!0,document.body.appendChild(a),R.messagingService=new l({target:a.contentWindow,targetOrigin:e}),R.isCommunicationReady=new Promise(i=>{var o;const n=r=>{var s;r.data.type==="headlessSDK:init"&&(i(),(s=R.messagingService)==null||s.removeListener(n))};(o=R.messagingService)==null||o.onReceive(n)})}request(a){return w(this,arguments,function*({api:e,payload:t}){return yield R.isCommunicationReady,new Promise((i,n)=>{var r,s;(r=R.messagingService)==null||r.send({type:e,data:t});const o=h=>{var g;const{type:u,data:p}=h.data;u===e&&(p.status==="resolved"?i(p.payload):n(p.payload),(g=R.messagingService)==null||g.removeListener(o))};(s=R.messagingService)==null||s.onReceive(o)})})}postMessage(e){var t;(t=R.messagingService)==null||t.send({type:e})}};let I=R;b(I,"messagingService",null),b(I,"isCommunicationReady");const j=["allow-downloads","allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-storage-access-by-user-activation","allow-top-navigation","allow-top-navigation-by-user-activation"];function m(y,e){if(y)throw new Error(e)}const q=new Set(["payment","payout"]),C=new Set(["en","fr","ar"]);class H{constructor(e){b(this,"options");b(this,"messagingService",null);b(this,"iframe",null);b(this,"isCommunicationReady",null);m(!q.has(e.type),`MoneyHash constructor must be called with valid type (${[...q].join(" | ")})!`),this.options=e}get lang(){var t;return((t=this.options.locale)==null?void 0:t.split("-")[0])||"en"}render({selector:e,intentId:t,sandbox:a,onHeightChange:i}){var h,u;(h=this.messagingService)==null||h.abortService();const n=c(),o=new URL(`${n}/embed/${this.options.type}/${t}`);o.searchParams.set("sdk","true"),o.searchParams.set("parent",window.location.origin),o.searchParams.set("version","js@1.11.1"),i&&o.searchParams.set("onDimensionsChange","true");const r=(u=this.options.locale)==null?void 0:u.split("-")[0];r&&o.searchParams.set("lang",r),this.iframe=document.createElement("iframe"),this.iframe.src=o.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",a&&a.forEach(p=>{var g;j.includes(p)&&((g=this.iframe)==null||g.sandbox.add(p))});const s=document.querySelector(e);return m(!s,`Couldn't find an element with selector ${e}!`),s.replaceChildren(this.iframe),this.messagingService=new l({target:this.iframe.contentWindow,targetOrigin:n}),this.isCommunicationReady=new Promise(p=>{var P;const g=k=>{var S;k.data.type==="sdk:init"&&(p(),(S=this.messagingService)==null||S.removeListener(g))};(P=this.messagingService)==null||P.onReceive(g)}),this.messagingService.onReceive((p,g)=>{var S,U,f,$;const{type:P,data:k}=p.data;switch(P){case"sdk:init":{g({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(U=(S=this.options).onComplete)==null||U.call(S,A({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{($=(f=this.options).onFail)==null||$.call(f,A({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{i==null||i(k.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return w(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return w(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class T{constructor(){b(this,"promise");b(this,"resolve");b(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Ce(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function F(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function se(y){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!y.includes(t))return t;return null}function ne(y){return(Array.isArray(y)?y.length:Object.keys(y).length)===0}function ae(y){if(typeof y!="object"||y===null)return!1;const e=Object.getPrototypeOf(y);return e===Object.prototype||e===null}function X(y,e){return new Promise((t,a)=>{if(document.getElementById(e)){t(void 0);return}const n=document.createElement("script");n.src=y,n.id=e,n.addEventListener("load",()=>{t(void 0)}),n.addEventListener("error",()=>{a(new Error("Script failed to load"))}),document.body.appendChild(n)})}function Re(y){return new Promise(e=>{setTimeout(()=>{e("done")},y*1e3)})}function Me(y,e){y&&console.warn(e)}const re=new Set(["method","customerBalance","savedCard"]);class Ie{constructor(e){M(this,N);M(this,O);M(this,D);M(this,B);M(this,W);M(this,V);M(this,G);M(this,K);M(this,Y);M(this,x);b(this,"options");b(this,"sdkApiHandler",new I);b(this,"sdkEmbed");b(this,"vaultSubmitListener",{current:null});b(this,"mountedCardElements",[]);b(this,"googlePaymentsClient",null);b(this,"cardForm",{collect:()=>w(this,null,function*(){m(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=se(this.mountedCardElements);m(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return v(this,O,te).call(this,{accessToken:t})}),pay:r=>w(this,[r],function*({intentId:e,cardData:t,saveCard:a,billingData:i,shippingData:n,installmentPlanData:o}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:i,shippingData:n,cardEmbed:t,saveCard:a,installmentPlanData:o}})}),createCardToken:a=>w(this,[a],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new H(J(A({},e),{headless:!0})),v(this,K,ve).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(m(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),m(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:A({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:a,useWalletBalance:i,metaData:n,installmentPlanData:o}){return m(!re.has(t),`type must be a valid one (${[...re].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:a,lang:this.sdkEmbed.lang,useWalletBalance:i,metaData:n,installmentPlanData:o}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return m(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(h){return w(this,arguments,function*({intentId:e,currency:t,amount:a,countryCode:i,onCancel:n=()=>{},onError:o,onComplete:r,billingData:s=!0}){if(yield X("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const u=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${a}`},requiredShippingContactFields:s===!0?["email"]:void 0}),{state:p,intent:g}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(!ae(s)||ne(s))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:s}})}}catch(k){throw yield this.resetSelectedMethod(e),k}const P=new T;return u.onvalidatemerchant=k=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:g.secret,validationUrl:k.validationURL,parentOrigin:window.location.origin}}).then(S=>u.completeMerchantValidation(S)).catch(o),u.onpaymentauthorized=k=>{var S;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:k.payment.token}),receiptBillingData:{email:(S=k.payment.shippingContact)==null?void 0:S.emailAddress}}}).then(U=>{u.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),P.resolve(U)}).catch(()=>{u.completePayment(ApplePaySession.STATUS_FAILURE),o==null||o(),P.reject(void 0)})},u.oncancel=n,u.begin(),P.promise})}renderGooglePayButton(a){return w(this,null,function*(){var i=a,{onClick:e}=i,t=we(i,["onClick"]);var r;const n=document.getElementById("moneyHash-google-pay-button");m(!n,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield X("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=v(this,N,ee).call(this);this.googlePaymentsClient.isReadyToPay(o).then(s=>{if(s.result){const h=this.googlePaymentsClient.createButton(J(A({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));n==null||n.replaceChildren(h)}else throw new Error("Google Pay is not ready to pay!")}).catch(s=>{console.dir(s)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t,billingData:a=!0}){return m(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),m(!e,"nativePayData is required to generate Google Pay receipt!"),m(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(J(A({},v(this,N,ee).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:a})).then(i=>({receipt:i.paymentMethodData.tokenizationData.token,receiptBillingData:{email:i.email}})).catch(i=>(i.statusCode==="CANCELED"?t==null||t():console.dir(i),Promise.reject(i)))}generateApplePayReceipt(i){return w(this,arguments,function*({nativePayData:e,onCancel:t=()=>{},billingData:a=!0}){if(yield X("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),m(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(m(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const n=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:a?["email"]:void 0}),o=new T;return n.onvalidatemerchant=r=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:r.validationURL,parentOrigin:window.location.origin}}).then(s=>n.completeMerchantValidation(s)).catch(s=>{n.abort(),o.reject(s)}),n.onpaymentauthorized=r=>{var h;const s={receipt:JSON.stringify({token:r.payment.token}),receiptBillingData:{email:(h=r.payment.shippingContact)==null?void 0:h.emailAddress}};n.completePayment(ApplePaySession.STATUS_SUCCESS),o.resolve(s)},n.oncancel=t,n.begin(),o.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(i){return w(this,arguments,function*({intentId:e,billingData:t=!0,onCancel:a}){m(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let n=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(n.state==="FORM_FIELDS"){if(!ae(t)||ne(t))throw new Error("Billing data is missing while calling payWithGooglePay");n=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(r){throw yield this.resetSelectedMethod(e),r}const{nativePayData:o}=n;return o?this.generateGooglePayReceipt({nativePayData:o,onCancel:a,billingData:typeof t=="boolean"?t:!1}).then(r=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:r})):n})}renderForm(e){return m(!e.selector,"selector is required for renderForm"),m(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){Me(!!e&&!C.has(e),`Invalid locale. Supported languages (${[...C].join(" | ")})`);const t=C.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return m(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(a=>{m(!a.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:a}){const i=[],n={},o=new Map;let r=!1;return v(this,G,Ae).call(this,i),{create:({elementType:s,elementOptions:h})=>{var S,U;const u=new Map;let p=null;const g=A(A({},t),h.classes),P=((S=g==null?void 0:g.focus)==null?void 0:S.split(" "))||["MoneyHashElement--focus"],k=((U=g==null?void 0:g.error)==null?void 0:U.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const f=document.querySelector(h.selector);m(!f,`Couldn't find an element with selector ${h.selector}!`),f.classList.add("MoneyHashElement"),i.push($=>{var oe,de,le,ce,pe,he,ue,me,ge;const{type:L,data:_}=$.data;if(L===`${s}@mount`&&(n[s]=_.isValid,(oe=u.get(`${s}@mount`))==null||oe()),L===`${s}@focus`){f.classList.add(...P),(de=u.get(`${s}@focus`))==null||de();return}if(L===`${s}@blur`){f.classList.remove(...P),(le=u.get(`${s}@blur`))==null||le();return}if(L===`${s}@error`){_.isValid?f.classList.remove(...k):f.classList.add(...k),(ce=u.get(`${s}@error`))==null||ce(_);return}if(L===`${s}@changeInput`){if((pe=u.get(`${s}@changeInput`))==null||pe({isValid:_.isValid,length:_.length}),n[s]=_.isValid,o.get("validityChange")){const Q=Object.values(n).every(Boolean);Q!==r&&((he=o.get("validityChange"))==null||he(Q),r=Q)}return}if(L===`${s}@cardNumberChange`){(ue=u.get(`${s}@cardNumberChange`))==null||ue(_);return}if(L===`${s}@key:Backspace`){(me=u.get(`${s}@key:Backspace`))==null||me();return}L===`${s}@key:Enter`&&((ge=u.get(`${s}@key:Enter`))==null||ge())}),p=v(this,Y,Ee).call(this,{container:f,elementType:s,elementOptions:h,styles:A(A({},e),h.styles),fontSourceCss:a}),this.mountedCardElements.push(s)},on:(f,$)=>{u.set(`${s}@${f}`,$)},off:f=>u.delete(`${s}@${f}`),focus:()=>{var f;(f=p==null?void 0:p.contentWindow)==null||f.postMessage({type:"focus"},F())},blur:()=>{var f;(f=p==null?void 0:p.contentWindow)==null||f.postMessage({type:"blur"},F())},clear:()=>{var f;(f=p==null?void 0:p.contentWindow)==null||f.postMessage({type:"clear"},F())}}},on:(s,h)=>{o.set(s,h)}}}submitForm(s){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:a,shippingData:i,saveCard:n,paymentMethod:o="CARD",installmentPlanData:r}){let h;if(t){const p=se(this.mountedCardElements);m(!!p,`You must mount ${p} element!`),h=yield v(this,O,te).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:a,shippingData:i,cardEmbed:h,saveCard:n,installmentPlanData:r}})})}selectInstallmentPlan(i){return w(this,arguments,function*({intentId:e,planId:t,issuerCode:a}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:a,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(i){return w(this,arguments,function*({first6Digits:e,amount:t,currency:a}){return m(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:a,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(i){return w(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:a}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:a,lang:this.sdkEmbed.lang}})})}renderUrl(n){return w(this,arguments,function*({intentId:e,url:t,renderStrategy:a,options:i}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),a){case"IFRAME":return v(this,D,be).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return v(this,B,Pe).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return v(this,W,ke).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const a=new Date(e),i=setInterval(()=>w(this,null,function*(){const n=new Date;a<n&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}N=new WeakSet,ee=function(e){var a,i;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[A({type:"CARD",parameters:{allowedAuthMethods:((a=this.options.googlePay)==null?void 0:a.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((i=this.options.googlePay)==null?void 0:i.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},O=new WeakSet,te=function(t){return w(this,arguments,function*({accessToken:e}){const a=new T;this.vaultSubmitListener.current=o=>{const{type:r,data:s}=o.data;r==="vaultSubmit:success"&&a.resolve(s),r==="vaultSubmit:error"&&a.reject(s)};const i=v(this,x,Se).call(this,{accessToken:e}),n=yield a.promise;return i.remove(),n})},D=new WeakSet,be=function(a){return w(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");m(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const n=document.createElement("iframe");n.src=t,n.style.setProperty("border","0","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("height","100%","important"),i==null||i.replaceChildren(n),yield v(this,V,ie).call(this,{intentId:e}),n.remove()})},B=new WeakSet,Pe=function(i){return w(this,arguments,function*({intentId:e,url:t,options:a={}}){const{width:n=600,height:o=400,left:r=200,top:s=200}=a.window||{},h=window.open(t,"",`width=${n},height=${o},left=${r},top=${s}`);m(!h,"Popup blocked by browser!"),yield v(this,V,ie).call(this,{intentId:e,isUsingPopUp:!0}),h==null||h.close()})},W=new WeakSet,ke=function(a){return w(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},V=new WeakSet,ie=function(a){return w(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new T,n=o=>w(this,null,function*(){var s,h,u,p;if(o.origin!==c())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[g]=yield Promise.all([this.getIntentDetails(e),Re(2)]),P=g.transaction.status.split(".")[1];P==="successful"||P.startsWith("pending")?(h=(s=this.options).onComplete)==null||h.call(s,A({type:this.options.type},g)):(p=(u=this.options).onFail)==null||p.call(u,A({type:this.options.type},g)),i.resolve(()=>null),window.removeEventListener("message",n)}});return window.addEventListener("message",n),i.promise})},G=new WeakSet,Ae=function(e){const t=a=>{a.origin===F()&&e.forEach(i=>{i(a)})};window.addEventListener("message",t)},K=new WeakSet,ve=function(e){const t=a=>{e.current&&e.current(a)};window.addEventListener("message",t)},Y=new WeakSet,Ee=function({container:e,elementType:t,elementOptions:a,styles:i,fontSourceCss:n}){var h,u,p,g,P;const o=F(),r=new URL(`${o}/vaultField/vaultField.html`);n&&r.searchParams.set("fontSourceCss",n),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((h=a.validation)==null?void 0:h.required)!==void 0&&r.searchParams.set("required",`${(u=a.validation)==null?void 0:u.required}`),r.searchParams.set("placeholder",(p=a.placeholder)!=null?p:""),r.searchParams.set("inputMode",(g=a.inputMode)!=null?g:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(i==null?void 0:i.direction)||""),r.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),r.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),r.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),r.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),r.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),r.searchParams.set("padding",(i==null?void 0:i.padding)||"");const s=document.createElement("iframe");return s.src=r.toString(),s.style.height=(P=i==null?void 0:i.height)!=null?P:"40px",s.style.setProperty("overflow","hidden","important"),s.style.setProperty("display","block","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("maxWidth","100%","important"),s.style.setProperty("border","0","important"),s.style.setProperty("margin","0","important"),s.style.setProperty("padding","0","important"),s.style.setProperty("userSelect","none","important"),s.style.setProperty("colorScheme","light only","important"),e.replaceChildren(s),s},x=new WeakSet,Se=function({accessToken:e}){const t=F(),a=Ce(),i=new URL(`${t}/vaultSubmit/vaultSubmit.html`);i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("vault_api_url",`${a}/api/v1/tokens/`),i.searchParams.set("access_token",e),i.searchParams.set("lang",this.sdkEmbed.lang);const n=document.createElement("iframe");return n.id="moneyhash-submit-iframe",n.src=i.toString(),n.hidden=!0,document.body.appendChild(n),n},d.IFrameSandboxOptions=j,d.default=Ie,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(d,l){typeof exports=="object"&&typeof module!="undefined"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(d=typeof globalThis!="undefined"?globalThis:d||self,l(d.MoneyHash={}))})(this,function(d){var D,ae,W,ve,N,se,V,ne,j,Ee,G,Se,K,Ce,B,re,Y,Re,x,Me,z,Ie,J,Le;"use strict";var $e=Object.defineProperty,He=Object.defineProperties;var De=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var ie=(d,l,c)=>l in d?$e(d,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[l]=c,A=(d,l)=>{for(var c in l||(l={}))be.call(l,c)&&ie(d,c,l[c]);if(X)for(var c of X(l))Pe.call(l,c)&&ie(d,c,l[c]);return d},Q=(d,l)=>He(d,De(l));var ke=(d,l)=>{var c={};for(var E in d)be.call(d,E)&&l.indexOf(E)<0&&(c[E]=d[E]);if(d!=null&&X)for(var E of X(d))l.indexOf(E)<0&&Pe.call(d,E)&&(c[E]=d[E]);return c};var w=(d,l,c)=>(ie(d,typeof l!="symbol"?l+"":l,c),c),Ae=(d,l,c)=>{if(!l.has(d))throw TypeError("Cannot "+c)};var Z=(d,l,c)=>(Ae(d,l,"read from private field"),c?c.call(d):l.get(d)),C=(d,l,c)=>{if(l.has(d))throw TypeError("Cannot add the same private member more than once");l instanceof WeakSet?l.add(d):l.set(d,c)};var v=(d,l,c)=>(Ae(d,l,"access private method"),c);var f=(d,l,c)=>new Promise((E,I)=>{var O=R=>{try{q(c.next(R))}catch(H){I(H)}},u=R=>{try{q(c.throw(R))}catch(H){I(H)}},q=R=>R.done?E(R.value):Promise.resolve(R.value).then(O,u);q((c=c.apply(d,l)).next())});class l{constructor(e){w(this,"target");w(this,"targetOrigin");w(this,"listeners");w(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function c(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function E(){return typeof window!="undefined"}const M=class{constructor(){E()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=c(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.11.2-beta.0");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),M.messagingService=new l({target:n.contentWindow,targetOrigin:e}),M.isCommunicationReady=new Promise(i=>{var o;const s=r=>{var a;r.data.type==="headlessSDK:init"&&(i(),(a=M.messagingService)==null||a.removeListener(s))};(o=M.messagingService)==null||o.onReceive(s)})}request(n){return f(this,arguments,function*({api:e,payload:t}){return yield M.isCommunicationReady,new Promise((i,s)=>{var r,a;(r=M.messagingService)==null||r.send({type:e,data:t});const o=m=>{var g;const{type:h,data:p}=m.data;h===e&&(p.status==="resolved"?i(p.payload):s(p.payload),(g=M.messagingService)==null||g.removeListener(o))};(a=M.messagingService)==null||a.onReceive(o)})})}postMessage(e){var t;(t=M.messagingService)==null||t.send({type:e})}};let I=M;w(I,"messagingService",null),w(I,"isCommunicationReady");const O=["allow-downloads","allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-storage-access-by-user-activation","allow-top-navigation","allow-top-navigation-by-user-activation"];function u(b,e){if(b)throw new Error(e)}const q=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class H{constructor(e){w(this,"options");w(this,"messagingService",null);w(this,"iframe",null);w(this,"isCommunicationReady",null);u(!q.has(e.type),`MoneyHash constructor must be called with valid type (${[...q].join(" | ")})!`),this.options=e}get lang(){var t;return((t=this.options.locale)==null?void 0:t.split("-")[0])||"en"}render({selector:e,intentId:t,sandbox:n,onHeightChange:i}){var m,h;(m=this.messagingService)==null||m.abortService();const s=c(),o=new URL(`${s}/embed/${this.options.type}/${t}`);o.searchParams.set("sdk","true"),o.searchParams.set("parent",window.location.origin),o.searchParams.set("version","js@1.11.2-beta.0"),i&&o.searchParams.set("onDimensionsChange","true");const r=(h=this.options.locale)==null?void 0:h.split("-")[0];r&&o.searchParams.set("lang",r),this.iframe=document.createElement("iframe"),this.iframe.src=o.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",n&&n.forEach(p=>{var g;O.includes(p)&&((g=this.iframe)==null||g.sandbox.add(p))});const a=document.querySelector(e);return u(!a,`Couldn't find an element with selector ${e}!`),a.replaceChildren(this.iframe),this.messagingService=new l({target:this.iframe.contentWindow,targetOrigin:s}),this.isCommunicationReady=new Promise(p=>{var P;const g=k=>{var S;k.data.type==="sdk:init"&&(p(),(S=this.messagingService)==null||S.removeListener(g))};(P=this.messagingService)==null||P.onReceive(g)}),this.messagingService.onReceive((p,g)=>{var S,U,y,$;const{type:P,data:k}=p.data;switch(P){case"sdk:init":{g({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(U=(S=this.options).onComplete)==null||U.call(S,A({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{($=(y=this.options).onFail)==null||$.call(y,A({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{i==null||i(k.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return f(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return f(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class T{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Ue(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function F(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function oe(b){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!b.includes(t))return t;return null}function de(b){return(Array.isArray(b)?b.length:Object.keys(b).length)===0}function ee(b,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=b,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(s)})}function _e(b){return new Promise(e=>{setTimeout(()=>{e("done")},b*1e3)})}function qe(b,e){b&&console.warn(e)}const le=new Set(["method","customerBalance","savedCard"]);class Fe{constructor(e){C(this,D);C(this,W);C(this,N);C(this,V);C(this,j);C(this,G);C(this,K);C(this,B);C(this,Y);C(this,x);C(this,z);C(this,J);w(this,"options");w(this,"sdkApiHandler",new I);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);w(this,"googlePaymentsClient",null);w(this,"cardForm",{collect:()=>f(this,null,function*(){u(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=oe(this.mountedCardElements);u(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return v(this,V,ne).call(this,{accessToken:t})}),pay:r=>f(this,[r],function*({intentId:e,cardData:t,saveCard:n,billingData:i,shippingData:s,installmentPlanData:o}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:i,shippingData:s,cardEmbed:t,saveCard:n,installmentPlanData:o}})}),createCardToken:n=>f(this,[n],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new H(Q(A({},e),{headless:!0})),v(this,x,Me).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(u(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),u(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:A({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:i,metaData:s,installmentPlanData:o}){return u(!le.has(t),`type must be a valid one (${[...le].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:n,lang:this.sdkEmbed.lang,useWalletBalance:i,metaData:s,installmentPlanData:o}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return u(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(m){return f(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:i,onCancel:s=()=>{},onError:o,onComplete:r,billingData:a={}}){if(yield ee("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const h=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${n}`},requiredShippingContactFields:Z(this,N,se)}),{state:p,intent:g}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(de(a))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:a}})}}catch(k){throw yield this.resetSelectedMethod(e),k}const P=new T;return h.onvalidatemerchant=k=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:g.secret,validationUrl:k.validationURL,parentOrigin:window.location.origin}}).then(S=>h.completeMerchantValidation(S)).catch(o),h.onpaymentauthorized=k=>{var S;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:k.payment.token}),receiptBillingData:{email:(S=k.payment.shippingContact)==null?void 0:S.emailAddress}}}).then(U=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),P.resolve(U)}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),o==null||o(),P.reject(void 0)})},h.oncancel=s,h.begin(),P.promise})}renderGooglePayButton(n){return f(this,null,function*(){var i=n,{onClick:e}=i,t=ke(i,["onClick"]);var r;const s=document.getElementById("moneyHash-google-pay-button");u(!s,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ee("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=v(this,D,ae).call(this);this.googlePaymentsClient.isReadyToPay(o).then(a=>{if(a.result){const m=this.googlePaymentsClient.createButton(Q(A({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));s==null||s.replaceChildren(m)}else throw new Error("Google Pay is not ready to pay!")}).catch(a=>{console.dir(a)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t}){return u(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),u(!e,"nativePayData is required to generate Google Pay receipt!"),u(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(Q(A({},v(this,D,ae).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:Z(this,W,ve).includes("email")})).then(n=>({receipt:n.paymentMethodData.tokenizationData.token,receiptBillingData:{email:n.email}})).catch(n=>(n.statusCode==="CANCELED"?t==null||t():console.dir(n),Promise.reject(n)))}generateApplePayReceipt(n){return f(this,arguments,function*({nativePayData:e,onCancel:t=()=>{}}){if(yield ee("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),u(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(u(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const i=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:Z(this,N,se)}),s=new T;return i.onvalidatemerchant=o=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:o.validationURL,parentOrigin:window.location.origin}}).then(r=>i.completeMerchantValidation(r)).catch(r=>{i.abort(),s.reject(r)}),i.onpaymentauthorized=o=>{var a;const r={receipt:JSON.stringify({token:o.payment.token}),receiptBillingData:{email:(a=o.payment.shippingContact)==null?void 0:a.emailAddress}};i.completePayment(ApplePaySession.STATUS_SUCCESS),s.resolve(r)},i.oncancel=t,i.begin(),s.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(i){return f(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){u(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let s=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(s.state==="FORM_FIELDS"){if(de(t))throw new Error("Billing data is missing while calling payWithGooglePay");s=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(r){throw yield this.resetSelectedMethod(e),r}const{nativePayData:o}=s;return o?this.generateGooglePayReceipt({nativePayData:o,onCancel:n}).then(r=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:r})):s})}renderForm(e){return u(!e.selector,"selector is required for renderForm"),u(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){qe(!!e&&!R.has(e),`Invalid locale. Supported languages (${[...R].join(" | ")})`);const t=R.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return u(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(n=>{u(!n.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:n}){const i=[],s={},o=new Map;let r=!1;return v(this,Y,Re).call(this,i),{create:({elementType:a,elementOptions:m})=>{var S,U;const h=new Map;let p=null;const g=A(A({},t),m.classes),P=((S=g==null?void 0:g.focus)==null?void 0:S.split(" "))||["MoneyHashElement--focus"],k=((U=g==null?void 0:g.error)==null?void 0:U.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const y=document.querySelector(m.selector);u(!y,`Couldn't find an element with selector ${m.selector}!`),y.classList.add("MoneyHashElement"),i.push($=>{var ce,pe,he,me,ue,ge,ye,fe,we;const{type:L,data:_}=$.data;if(L===`${a}@mount`&&(s[a]=_.isValid,(ce=h.get(`${a}@mount`))==null||ce()),L===`${a}@focus`){y.classList.add(...P),(pe=h.get(`${a}@focus`))==null||pe();return}if(L===`${a}@blur`){y.classList.remove(...P),(he=h.get(`${a}@blur`))==null||he();return}if(L===`${a}@error`){_.isValid?y.classList.remove(...k):y.classList.add(...k),(me=h.get(`${a}@error`))==null||me(_);return}if(L===`${a}@changeInput`){if((ue=h.get(`${a}@changeInput`))==null||ue({isValid:_.isValid,length:_.length}),s[a]=_.isValid,o.get("validityChange")){const te=Object.values(s).every(Boolean);te!==r&&((ge=o.get("validityChange"))==null||ge(te),r=te)}return}if(L===`${a}@cardNumberChange`){(ye=h.get(`${a}@cardNumberChange`))==null||ye(_);return}if(L===`${a}@key:Backspace`){(fe=h.get(`${a}@key:Backspace`))==null||fe();return}L===`${a}@key:Enter`&&((we=h.get(`${a}@key:Enter`))==null||we())}),p=v(this,z,Ie).call(this,{container:y,elementType:a,elementOptions:m,styles:A(A({},e),m.styles),fontSourceCss:n}),this.mountedCardElements.push(a)},on:(y,$)=>{h.set(`${a}@${y}`,$)},off:y=>h.delete(`${a}@${y}`),focus:()=>{var y;(y=p==null?void 0:p.contentWindow)==null||y.postMessage({type:"focus"},F())},blur:()=>{var y;(y=p==null?void 0:p.contentWindow)==null||y.postMessage({type:"blur"},F())},clear:()=>{var y;(y=p==null?void 0:p.contentWindow)==null||y.postMessage({type:"clear"},F())}}},on:(a,m)=>{o.set(a,m)}}}submitForm(a){return f(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:i,saveCard:s,paymentMethod:o="CARD",installmentPlanData:r}){let m;if(t){const p=oe(this.mountedCardElements);u(!!p,`You must mount ${p} element!`),m=yield v(this,V,ne).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:n,shippingData:i,cardEmbed:m,saveCard:s,installmentPlanData:r}})})}selectInstallmentPlan(i){return f(this,arguments,function*({intentId:e,planId:t,issuerCode:n}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:n,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(i){return f(this,arguments,function*({first6Digits:e,amount:t,currency:n}){return u(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:n,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(i){return f(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:n}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:n,lang:this.sdkEmbed.lang}})})}renderUrl(s){return f(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:i}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return v(this,j,Ee).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return v(this,G,Se).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return v(this,K,Ce).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),i=setInterval(()=>f(this,null,function*(){const s=new Date;n<s&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}D=new WeakSet,ae=function(e){var n,i;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[A({type:"CARD",parameters:{allowedAuthMethods:((n=this.options.googlePay)==null?void 0:n.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((i=this.options.googlePay)==null?void 0:i.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},W=new WeakSet,ve=function(){var e;return((e=this.options.googlePay)==null?void 0:e.collectibleBillingData)||["email"]},N=new WeakSet,se=function(){var e;return((e=this.options.applePay)==null?void 0:e.collectibleBillingData)||["email"]},V=new WeakSet,ne=function(t){return f(this,arguments,function*({accessToken:e}){const n=new T;this.vaultSubmitListener.current=o=>{const{type:r,data:a}=o.data;r==="vaultSubmit:success"&&n.resolve(a),r==="vaultSubmit:error"&&n.reject(a)};const i=v(this,J,Le).call(this,{accessToken:e}),s=yield n.promise;return i.remove(),s})},j=new WeakSet,Ee=function(n){return f(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");u(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=t,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),i==null||i.replaceChildren(s),yield v(this,B,re).call(this,{intentId:e}),s.remove()})},G=new WeakSet,Se=function(i){return f(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:s=600,height:o=400,left:r=200,top:a=200}=n.window||{},m=window.open(t,"",`width=${s},height=${o},left=${r},top=${a}`);u(!m,"Popup blocked by browser!"),yield v(this,B,re).call(this,{intentId:e,isUsingPopUp:!0}),m==null||m.close()})},K=new WeakSet,Ce=function(n){return f(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},B=new WeakSet,re=function(n){return f(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new T,s=o=>f(this,null,function*(){var a,m,h,p;if(o.origin!==c())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[g]=yield Promise.all([this.getIntentDetails(e),_e(2)]),P=g.transaction.status.split(".")[1];P==="successful"||P.startsWith("pending")?(m=(a=this.options).onComplete)==null||m.call(a,A({type:this.options.type},g)):(p=(h=this.options).onFail)==null||p.call(h,A({type:this.options.type},g)),i.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),i.promise})},Y=new WeakSet,Re=function(e){const t=n=>{n.origin===F()&&e.forEach(i=>{i(n)})};window.addEventListener("message",t)},x=new WeakSet,Me=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},z=new WeakSet,Ie=function({container:e,elementType:t,elementOptions:n,styles:i,fontSourceCss:s}){var m,h,p,g,P;const o=F(),r=new URL(`${o}/vaultField/vaultField.html`);s&&r.searchParams.set("fontSourceCss",s),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((m=n.validation)==null?void 0:m.required)!==void 0&&r.searchParams.set("required",`${(h=n.validation)==null?void 0:h.required}`),r.searchParams.set("placeholder",(p=n.placeholder)!=null?p:""),r.searchParams.set("inputMode",(g=n.inputMode)!=null?g:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(i==null?void 0:i.direction)||""),r.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),r.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),r.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),r.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),r.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),r.searchParams.set("padding",(i==null?void 0:i.padding)||"");const a=document.createElement("iframe");return a.src=r.toString(),a.style.height=(P=i==null?void 0:i.height)!=null?P:"40px",a.style.setProperty("overflow","hidden","important"),a.style.setProperty("display","block","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("maxWidth","100%","important"),a.style.setProperty("border","0","important"),a.style.setProperty("margin","0","important"),a.style.setProperty("padding","0","important"),a.style.setProperty("userSelect","none","important"),a.style.setProperty("colorScheme","light only","important"),e.replaceChildren(a),a},J=new WeakSet,Le=function({accessToken:e}){const t=F(),n=Ue(),i=new URL(`${t}/vaultSubmit/vaultSubmit.html`);i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("vault_api_url",`${n}/api/v1/tokens/`),i.searchParams.set("access_token",e),i.searchParams.set("lang",this.sdkEmbed.lang);const s=document.createElement("iframe");return s.id="moneyhash-submit-iframe",s.src=i.toString(),s.hidden=!0,document.body.appendChild(s),s},d.IFrameSandboxOptions=O,d.default=Fe,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var d=Object.defineProperty;var a=(t,e,s)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var n=(t,e,s)=>(a(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-47ecdac8.cjs");class o{constructor(e){n(this,"options");n(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start(e){return r.throwIf(!e.selector,"selector is required for start"),r.throwIf(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o; | ||
"use strict";var d=Object.defineProperty;var a=(t,e,s)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var n=(t,e,s)=>(a(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-0c917262.cjs");class o{constructor(e){n(this,"options");n(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start(e){return r.throwIf(!e.selector,"selector is required for start"),r.throwIf(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o; |
var n = Object.defineProperty; | ||
var i = (t, e, s) => e in t ? n(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s; | ||
var r = (t, e, s) => (i(t, typeof e != "symbol" ? e + "" : e, s), s); | ||
import { S as o, t as d, w as u, s as a } from "./warnIf-7be59aa6.js"; | ||
import { S as o, t as d, w as u, s as a } from "./warnIf-0eba27c6.js"; | ||
class c { | ||
@@ -6,0 +6,0 @@ constructor(e) { |
@@ -1,1 +0,1 @@ | ||
(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var $=Object.defineProperty;var U=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var b=(i,s,t)=>s in i?$(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,S=(i,s)=>{for(var t in s||(s={}))A.call(s,t)&&b(i,t,s[t]);if(U)for(var t of U(s))_.call(s,t)&&b(i,t,s[t]);return i};var o=(i,s,t)=>(b(i,typeof s!="symbol"?s+"":s,t),t);var E=(i,s,t)=>new Promise((l,m)=>{var g=r=>{try{u(t.next(r))}catch(a){m(a)}},v=r=>{try{u(t.throw(r))}catch(a){m(a)}},u=r=>r.done?l(r.value):Promise.resolve(r.value).then(g,v);u((t=t.apply(i,s)).next())});const i=["allow-downloads","allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-storage-access-by-user-activation","allow-top-navigation","allow-top-navigation-by-user-activation"];class s{constructor(e){o(this,"target");o(this,"targetOrigin");o(this,"listeners");o(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(n=>n!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(n=>{n(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function t(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function l(a,e){if(a)throw new Error(e)}const m=new Set(["payment","payout"]),g=new Set(["en","fr","ar"]);class v{constructor(e){o(this,"options");o(this,"messagingService",null);o(this,"iframe",null);o(this,"isCommunicationReady",null);l(!m.has(e.type),`MoneyHash constructor must be called with valid type (${[...m].join(" | ")})!`),this.options=e}get lang(){var n;return((n=this.options.locale)==null?void 0:n.split("-")[0])||"en"}render({selector:e,intentId:n,sandbox:R,onHeightChange:w}){var M,O;(M=this.messagingService)==null||M.abortService();const I=t(),d=new URL(`${I}/embed/${this.options.type}/${n}`);d.searchParams.set("sdk","true"),d.searchParams.set("parent",window.location.origin),d.searchParams.set("version","js@1.11.1"),w&&d.searchParams.set("onDimensionsChange","true");const L=(O=this.options.locale)==null?void 0:O.split("-")[0];L&&d.searchParams.set("lang",L),this.iframe=document.createElement("iframe"),this.iframe.src=d.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",R&&R.forEach(h=>{var c;i.includes(h)&&((c=this.iframe)==null||c.sandbox.add(h))});const k=document.querySelector(e);return l(!k,`Couldn't find an element with selector ${e}!`),k.replaceChildren(this.iframe),this.messagingService=new s({target:this.iframe.contentWindow,targetOrigin:I}),this.isCommunicationReady=new Promise(h=>{var y;const c=p=>{var f;p.data.type==="sdk:init"&&(h(),(f=this.messagingService)==null||f.removeListener(c))};(y=this.messagingService)==null||y.onReceive(c)}),this.messagingService.onReceive((h,c)=>{var f,F,C,P;const{type:y,data:p}=h.data;switch(y){case"sdk:init":{c({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(F=(f=this.options).onComplete)==null||F.call(f,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(P=(C=this.options).onFail)==null||P.call(C,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{w==null||w(p.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return E(this,null,function*(){var n;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(n=this.messagingService)==null||n.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return E(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function u(a,e){a&&console.warn(e)}class r{constructor(e){o(this,"options");o(this,"sdkEmbed");this.options=e,this.sdkEmbed=new v(e)}start(e){return l(!e.selector,"selector is required for start"),l(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){u(!!e&&!g.has(e),`Invalid locale. Supported languages (${[...g].join(" | ")})`);const n=g.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return r}); | ||
(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var $=Object.defineProperty;var U=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var b=(i,s,t)=>s in i?$(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,S=(i,s)=>{for(var t in s||(s={}))A.call(s,t)&&b(i,t,s[t]);if(U)for(var t of U(s))_.call(s,t)&&b(i,t,s[t]);return i};var o=(i,s,t)=>(b(i,typeof s!="symbol"?s+"":s,t),t);var E=(i,s,t)=>new Promise((l,m)=>{var g=r=>{try{u(t.next(r))}catch(a){m(a)}},v=r=>{try{u(t.throw(r))}catch(a){m(a)}},u=r=>r.done?l(r.value):Promise.resolve(r.value).then(g,v);u((t=t.apply(i,s)).next())});const i=["allow-downloads","allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-storage-access-by-user-activation","allow-top-navigation","allow-top-navigation-by-user-activation"];class s{constructor(e){o(this,"target");o(this,"targetOrigin");o(this,"listeners");o(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(n=>n!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(n=>{n(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function t(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function l(a,e){if(a)throw new Error(e)}const m=new Set(["payment","payout"]),g=new Set(["en","fr","ar"]);class v{constructor(e){o(this,"options");o(this,"messagingService",null);o(this,"iframe",null);o(this,"isCommunicationReady",null);l(!m.has(e.type),`MoneyHash constructor must be called with valid type (${[...m].join(" | ")})!`),this.options=e}get lang(){var n;return((n=this.options.locale)==null?void 0:n.split("-")[0])||"en"}render({selector:e,intentId:n,sandbox:R,onHeightChange:w}){var M,O;(M=this.messagingService)==null||M.abortService();const I=t(),d=new URL(`${I}/embed/${this.options.type}/${n}`);d.searchParams.set("sdk","true"),d.searchParams.set("parent",window.location.origin),d.searchParams.set("version","js@1.11.2-beta.0"),w&&d.searchParams.set("onDimensionsChange","true");const L=(O=this.options.locale)==null?void 0:O.split("-")[0];L&&d.searchParams.set("lang",L),this.iframe=document.createElement("iframe"),this.iframe.src=d.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",R&&R.forEach(h=>{var c;i.includes(h)&&((c=this.iframe)==null||c.sandbox.add(h))});const k=document.querySelector(e);return l(!k,`Couldn't find an element with selector ${e}!`),k.replaceChildren(this.iframe),this.messagingService=new s({target:this.iframe.contentWindow,targetOrigin:I}),this.isCommunicationReady=new Promise(h=>{var y;const c=p=>{var f;p.data.type==="sdk:init"&&(h(),(f=this.messagingService)==null||f.removeListener(c))};(y=this.messagingService)==null||y.onReceive(c)}),this.messagingService.onReceive((h,c)=>{var f,F,C,P;const{type:y,data:p}=h.data;switch(y){case"sdk:init":{c({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(F=(f=this.options).onComplete)==null||F.call(f,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(P=(C=this.options).onFail)==null||P.call(C,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{w==null||w(p.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return E(this,null,function*(){var n;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(n=this.messagingService)==null||n.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return E(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function u(a,e){a&&console.warn(e)}class r{constructor(e){o(this,"options");o(this,"sdkEmbed");this.options=e,this.sdkEmbed=new v(e)}start(e){return l(!e.selector,"selector is required for start"),l(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){u(!!e&&!g.has(e),`Invalid locale. Supported languages (${[...g].join(" | ")})`);const n=g.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return r}); |
{ | ||
"name": "@moneyhash/js-sdk", | ||
"version": "1.11.1", | ||
"version": "1.11.2-beta.0", | ||
"description": "MoneyHash JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
424812
3449
3