Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moneyhash/js-sdk

Package Overview
Dependencies
Maintainers
0
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moneyhash/js-sdk - npm Package Compare versions

Comparing version 1.8.1-beta.6 to 1.8.1

dist/warnIf-43195b62.cjs

2

dist/headless.cjs.js

@@ -1,1 +0,1 @@

"use strict";var fe=Object.defineProperty,we=Object.defineProperties;var Pe=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var O=(o,e,t)=>e in o?fe(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,w=(o,e)=>{for(var t in e||(e={}))ne.call(e,t)&&O(o,t,e[t]);if(_)for(var t of _(e))re.call(e,t)&&O(o,t,e[t]);return o},F=(o,e)=>we(o,Pe(e));var ie=(o,e)=>{var t={};for(var r in o)ne.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&_)for(var r of _(o))e.indexOf(r)<0&&re.call(o,r)&&(t[r]=o[r]);return t};var f=(o,e,t)=>(O(o,typeof e!="symbol"?e+"":e,t),t),be=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var P=(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)=>(be(o,e,"access private method"),t);var g=(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 h=require("./warnIf-d0a82549.cjs");function ke(){return typeof window!="undefined"}const b=class{constructor(){ke()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=h.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.8.1-beta.6");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),b.messagingService=new h.MessagingService({target:r.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(a=>{var d;const i=s=>{var n;s.data.type==="headlessSDK:init"&&(a(),(n=b.messagingService)==null||n.removeListener(i))};(d=b.messagingService)==null||d.onReceive(i)})}request(r){return g(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((a,i)=>{var s,n;(s=b.messagingService)==null||s.send({type:e,data:t});const d=l=>{var m;const{type:c,data:p}=l.data;c===e&&(p.status==="resolved"?a(p.payload):i(p.payload),(m=b.messagingService)==null||m.removeListener(d))};(n=b.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=b.messagingService)==null||t.send({type:e})}};let C=b;f(C,"messagingService",null),f(C,"isCommunicationReady");class B{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 S(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function Ae(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function se(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function oe(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function de(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 ve(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const ce=new Set(["method","customerBalance","savedCard"]);var L,G,M,Y,$,le,q,he,H,pe,R,x,N,ue,D,me,V,ge,W,ye;class Ie{constructor(e){P(this,L);P(this,M);P(this,$);P(this,q);P(this,H);P(this,R);P(this,N);P(this,D);P(this,V);P(this,W);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:()=>g(this,null,function*(){h.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=se(this.mountedCardElements);h.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,M,Y).call(this,{accessToken:t})}),pay:d=>g(this,[d],function*({intentId:e,cardData:t,saveCard:r,billingData:a,shippingData:i}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:i,cardEmbed:t,saveCard:r}})}),createCardToken:r=>g(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 h.SDKEmbed(F(w({},e),{headless:!0})),y(this,D,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):(h.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),h.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:w({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:r,useWalletBalance:a,metaData:i}){return h.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}})}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 h.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 g(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:a,onCancel:i=()=>{},onError:d,onComplete:s,billingData:n={}}){if(yield de("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 c=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`},requiredShippingContactFields:["email"]}),{state:p,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(oe(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 E=new B;return c.onvalidatemerchant=A=>{fetch(`${Ae()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:A.validationURL})}).then(k=>k.ok?k.json():Promise.reject()).then(k=>c.completeMerchantValidation(k)).catch(d)},c.onpaymentauthorized=A=>{var k;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:A.payment.token}),receiptBillingData:{email:(k=A.payment.shippingContact)==null?void 0:k.emailAddress}}}).then(U=>{c.completePayment(ApplePaySession.STATUS_SUCCESS),s==null||s(),E.resolve(U)}).catch(()=>{c.completePayment(ApplePaySession.STATUS_FAILURE),d==null||d(),E.reject(void 0)})},c.oncancel=i,c.begin(),E.promise})}renderGooglePayButton(r){return g(this,null,function*(){var a=r,{onClick:e}=a,t=ie(a,["onClick"]);var s;const i=document.getElementById("moneyHash-google-pay-button");h.throwIf(!i,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield de("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,L,G).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const l=this.googlePaymentsClient.createButton(F(w({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)})})}payWithGooglePay(a){return g(this,arguments,function*({intentId:e,billingData:t={},onCancel:r}){h.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(oe(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.googlePaymentsClient.loadPaymentData(F(w({},y(this,L,G).call(this,d)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${d.amount}`,currencyCode:d.currency_code,countryCode:d.country_code},merchantInfo:{merchantName:d==null?void 0:d.merchant_name,merchantId:d==null?void 0:d.merchant_id},emailRequired:!0})).then(s=>{const n=s.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:n,receiptBillingData:{email:s.email}}})}).catch(s=>(s.statusCode==="CANCELED"?r==null||r():console.dir(s),Promise.reject(s))):i})}renderForm(e){return h.throwIf(!e.selector,"selector is required for renderForm"),h.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){h.warnIf(!!e&&!h.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...h.supportedLanguages].join(" | ")})`);const t=h.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return h.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=>{h.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,N,ue).call(this,a),{create:({elementType:n,elementOptions:l})=>{var k,U;const c=new Map;let p=null;const m=w(w({},t),l.classes),E=((k=m==null?void 0:m.focus)==null?void 0:k.split(" "))||["MoneyHashElement--focus"],A=((U=m==null?void 0:m.error)==null?void 0:U.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const u=document.querySelector(l.selector);h.throwIf(!u,`Couldn't find an element with selector ${l.selector}!`),u.classList.add("MoneyHashElement"),a.push(T=>{var K,z,J,X,Q,Z,ee,te,ae;const{type:v,data:I}=T.data;if(v===`${n}@mount`&&(i[n]=I.isValid,(K=c.get(`${n}@mount`))==null||K()),v===`${n}@focus`){u.classList.add(...E),(z=c.get(`${n}@focus`))==null||z();return}if(v===`${n}@blur`){u.classList.remove(...E),(J=c.get(`${n}@blur`))==null||J();return}if(v===`${n}@error`){I.isValid?u.classList.remove(...A):u.classList.add(...A),(X=c.get(`${n}@error`))==null||X(I);return}if(v===`${n}@changeInput`){if((Q=c.get(`${n}@changeInput`))==null||Q({isValid:I.isValid,length:I.length}),i[n]=I.isValid,d.get("validityChange")){const j=Object.values(i).every(Boolean);j!==s&&((Z=d.get("validityChange"))==null||Z(j),s=j)}return}if(v===`${n}@cardNumberChange`){(ee=c.get(`${n}@cardNumberChange`))==null||ee(I);return}if(v===`${n}@key:Backspace`){(te=c.get(`${n}@key:Backspace`))==null||te();return}v===`${n}@key:Enter`&&((ae=c.get(`${n}@key:Enter`))==null||ae())}),p=y(this,V,ge).call(this,{container:u,elementType:n,elementOptions:l,styles:w(w({},e),l.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(u,T)=>{c.set(`${n}@${u}`,T)},off:u=>c.delete(`${n}@${u}`),focus:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"focus"},S())},blur:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"blur"},S())},clear:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"clear"},S())}}},on:(n,l)=>{d.set(n,l)}}}submitForm(s){return g(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:a,saveCard:i,paymentMethod:d="CARD"}){let n;if(t){const c=se(this.mountedCardElements);h.throwIf(!!c,`You must mount ${c} element!`),n=yield y(this,M,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:n,saveCard:i}})})}submitCvv(r){return g(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(i){return g(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),r){case"IFRAME":return y(this,$,le).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,q,he).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,H,pe).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const r=new Date(e),a=setInterval(()=>g(this,null,function*(){const i=new Date;r<i&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}L=new WeakSet,G=function(e){var r,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[w({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}}}:{})]}},M=new WeakSet,Y=function(t){return g(this,arguments,function*({accessToken:e}){const r=new B;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,W,ye).call(this,{accessToken:e}),i=yield r.promise;return a.remove(),i})},$=new WeakSet,le=function(r){return g(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");h.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,R,x).call(this,{intentId:e}),i.remove()})},q=new WeakSet,he=function(a){return g(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}`);h.throwIf(!l,"Popup blocked by browser!"),yield y(this,R,x).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},H=new WeakSet,pe=function(r){return g(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},R=new WeakSet,x=function(r){return g(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new B,i=d=>g(this,null,function*(){var n,l,c,p;if(d.origin!==h.getIframeUrl())return;const{type:s}=d.data;if(s==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),ve(2)]),E=m.transaction.status.split(".")[1];E==="successful"||E.startsWith("pending")?(l=(n=this.options).onComplete)==null||l.call(n,w({type:this.options.type},m)):(p=(c=this.options).onFail)==null||p.call(c,w({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",i)}});return window.addEventListener("message",i),a.promise})},N=new WeakSet,ue=function(e){const t=r=>{r.origin===S()&&e.forEach(a=>{a(r)})};window.addEventListener("message",t)},D=new WeakSet,me=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},V=new WeakSet,ge=function({container:e,elementType:t,elementOptions:r,styles:a,fontSourceCss:i}){var l,c,p,m;const d=S(),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",`${(c=r.validation)==null?void 0:c.required}`),s.searchParams.set("placeholder",(p=r.placeholder)!=null?p:""),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=(m=a==null?void 0:a.height)!=null?m:"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},W=new WeakSet,ye=function({accessToken:e}){const t=S(),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=h.IFrameSandboxOptions;exports.default=Ie;
"use strict";var fe=Object.defineProperty,we=Object.defineProperties;var Pe=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var O=(o,e,t)=>e in o?fe(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,w=(o,e)=>{for(var t in e||(e={}))ne.call(e,t)&&O(o,t,e[t]);if(_)for(var t of _(e))re.call(e,t)&&O(o,t,e[t]);return o},F=(o,e)=>we(o,Pe(e));var ie=(o,e)=>{var t={};for(var r in o)ne.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&_)for(var r of _(o))e.indexOf(r)<0&&re.call(o,r)&&(t[r]=o[r]);return t};var f=(o,e,t)=>(O(o,typeof e!="symbol"?e+"":e,t),t),be=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var P=(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)=>(be(o,e,"access private method"),t);var g=(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 h=require("./warnIf-43195b62.cjs");function ke(){return typeof window!="undefined"}const b=class{constructor(){ke()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=h.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.8.1");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),b.messagingService=new h.MessagingService({target:r.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(a=>{var d;const i=s=>{var n;s.data.type==="headlessSDK:init"&&(a(),(n=b.messagingService)==null||n.removeListener(i))};(d=b.messagingService)==null||d.onReceive(i)})}request(r){return g(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((a,i)=>{var s,n;(s=b.messagingService)==null||s.send({type:e,data:t});const d=l=>{var m;const{type:c,data:p}=l.data;c===e&&(p.status==="resolved"?a(p.payload):i(p.payload),(m=b.messagingService)==null||m.removeListener(d))};(n=b.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=b.messagingService)==null||t.send({type:e})}};let C=b;f(C,"messagingService",null),f(C,"isCommunicationReady");class B{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 S(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function Ae(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function se(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function oe(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function de(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 ve(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const ce=new Set(["method","customerBalance","savedCard"]);var L,G,M,Y,$,le,q,he,H,pe,R,x,N,ue,D,me,V,ge,W,ye;class Ie{constructor(e){P(this,L);P(this,M);P(this,$);P(this,q);P(this,H);P(this,R);P(this,N);P(this,D);P(this,V);P(this,W);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:()=>g(this,null,function*(){h.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=se(this.mountedCardElements);h.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,M,Y).call(this,{accessToken:t})}),pay:d=>g(this,[d],function*({intentId:e,cardData:t,saveCard:r,billingData:a,shippingData:i}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:i,cardEmbed:t,saveCard:r}})}),createCardToken:r=>g(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 h.SDKEmbed(F(w({},e),{headless:!0})),y(this,D,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):(h.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),h.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:w({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:r,useWalletBalance:a,metaData:i}){return h.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}})}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 h.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 g(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:a,onCancel:i=()=>{},onError:d,onComplete:s,billingData:n={}}){if(yield de("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 c=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`},requiredShippingContactFields:["email"]}),{state:p,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(oe(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 E=new B;return c.onvalidatemerchant=A=>{fetch(`${Ae()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:A.validationURL})}).then(k=>k.ok?k.json():Promise.reject()).then(k=>c.completeMerchantValidation(k)).catch(d)},c.onpaymentauthorized=A=>{var k;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:A.payment.token}),receiptBillingData:{email:(k=A.payment.shippingContact)==null?void 0:k.emailAddress}}}).then(U=>{c.completePayment(ApplePaySession.STATUS_SUCCESS),s==null||s(),E.resolve(U)}).catch(()=>{c.completePayment(ApplePaySession.STATUS_FAILURE),d==null||d(),E.reject(void 0)})},c.oncancel=i,c.begin(),E.promise})}renderGooglePayButton(r){return g(this,null,function*(){var a=r,{onClick:e}=a,t=ie(a,["onClick"]);var s;const i=document.getElementById("moneyHash-google-pay-button");h.throwIf(!i,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield de("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,L,G).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const l=this.googlePaymentsClient.createButton(F(w({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)})})}payWithGooglePay(a){return g(this,arguments,function*({intentId:e,billingData:t={},onCancel:r}){h.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(oe(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.googlePaymentsClient.loadPaymentData(F(w({},y(this,L,G).call(this,d)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${d.amount}`,currencyCode:d.currency_code,countryCode:d.country_code},merchantInfo:{merchantName:d==null?void 0:d.merchant_name,merchantId:d==null?void 0:d.merchant_id},emailRequired:!0})).then(s=>{const n=s.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:n,receiptBillingData:{email:s.email}}})}).catch(s=>(s.statusCode==="CANCELED"?r==null||r():console.dir(s),Promise.reject(s))):i})}renderForm(e){return h.throwIf(!e.selector,"selector is required for renderForm"),h.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){h.warnIf(!!e&&!h.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...h.supportedLanguages].join(" | ")})`);const t=h.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return h.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=>{h.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,N,ue).call(this,a),{create:({elementType:n,elementOptions:l})=>{var k,U;const c=new Map;let p=null;const m=w(w({},t),l.classes),E=((k=m==null?void 0:m.focus)==null?void 0:k.split(" "))||["MoneyHashElement--focus"],A=((U=m==null?void 0:m.error)==null?void 0:U.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const u=document.querySelector(l.selector);h.throwIf(!u,`Couldn't find an element with selector ${l.selector}!`),u.classList.add("MoneyHashElement"),a.push(T=>{var K,z,J,X,Q,Z,ee,te,ae;const{type:v,data:I}=T.data;if(v===`${n}@mount`&&(i[n]=I.isValid,(K=c.get(`${n}@mount`))==null||K()),v===`${n}@focus`){u.classList.add(...E),(z=c.get(`${n}@focus`))==null||z();return}if(v===`${n}@blur`){u.classList.remove(...E),(J=c.get(`${n}@blur`))==null||J();return}if(v===`${n}@error`){I.isValid?u.classList.remove(...A):u.classList.add(...A),(X=c.get(`${n}@error`))==null||X(I);return}if(v===`${n}@changeInput`){if((Q=c.get(`${n}@changeInput`))==null||Q({isValid:I.isValid,length:I.length}),i[n]=I.isValid,d.get("validityChange")){const j=Object.values(i).every(Boolean);j!==s&&((Z=d.get("validityChange"))==null||Z(j),s=j)}return}if(v===`${n}@cardNumberChange`){(ee=c.get(`${n}@cardNumberChange`))==null||ee(I);return}if(v===`${n}@key:Backspace`){(te=c.get(`${n}@key:Backspace`))==null||te();return}v===`${n}@key:Enter`&&((ae=c.get(`${n}@key:Enter`))==null||ae())}),p=y(this,V,ge).call(this,{container:u,elementType:n,elementOptions:l,styles:w(w({},e),l.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(u,T)=>{c.set(`${n}@${u}`,T)},off:u=>c.delete(`${n}@${u}`),focus:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"focus"},S())},blur:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"blur"},S())},clear:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"clear"},S())}}},on:(n,l)=>{d.set(n,l)}}}submitForm(s){return g(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:a,saveCard:i,paymentMethod:d="CARD"}){let n;if(t){const c=se(this.mountedCardElements);h.throwIf(!!c,`You must mount ${c} element!`),n=yield y(this,M,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:n,saveCard:i}})})}submitCvv(r){return g(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(i){return g(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),r){case"IFRAME":return y(this,$,le).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,q,he).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,H,pe).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const r=new Date(e),a=setInterval(()=>g(this,null,function*(){const i=new Date;r<i&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}L=new WeakSet,G=function(e){var r,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[w({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}}}:{})]}},M=new WeakSet,Y=function(t){return g(this,arguments,function*({accessToken:e}){const r=new B;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,W,ye).call(this,{accessToken:e}),i=yield r.promise;return a.remove(),i})},$=new WeakSet,le=function(r){return g(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");h.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,R,x).call(this,{intentId:e}),i.remove()})},q=new WeakSet,he=function(a){return g(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}`);h.throwIf(!l,"Popup blocked by browser!"),yield y(this,R,x).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},H=new WeakSet,pe=function(r){return g(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},R=new WeakSet,x=function(r){return g(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new B,i=d=>g(this,null,function*(){var n,l,c,p;if(d.origin!==h.getIframeUrl())return;const{type:s}=d.data;if(s==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),ve(2)]),E=m.transaction.status.split(".")[1];E==="successful"||E.startsWith("pending")?(l=(n=this.options).onComplete)==null||l.call(n,w({type:this.options.type},m)):(p=(c=this.options).onFail)==null||p.call(c,w({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",i)}});return window.addEventListener("message",i),a.promise})},N=new WeakSet,ue=function(e){const t=r=>{r.origin===S()&&e.forEach(a=>{a(r)})};window.addEventListener("message",t)},D=new WeakSet,me=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},V=new WeakSet,ge=function({container:e,elementType:t,elementOptions:r,styles:a,fontSourceCss:i}){var l,c,p,m;const d=S(),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",`${(c=r.validation)==null?void 0:c.required}`),s.searchParams.set("placeholder",(p=r.placeholder)!=null?p:""),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=(m=a==null?void 0:a.height)!=null?m:"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},W=new WeakSet,ye=function({accessToken:e}){const t=S(),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=h.IFrameSandboxOptions;exports.default=Ie;

@@ -48,4 +48,4 @@ var Pe = Object.defineProperty, be = Object.defineProperties;

});
import { M as Ae, g as pe, S as ve, t as g, w as Se, s as O } from "./warnIf-bcd4d922.js";
import { I as He } from "./warnIf-bcd4d922.js";
import { M as Ae, g as pe, S as ve, t as g, w as Se, s as O } from "./warnIf-a4f9d411.js";
import { I as He } from "./warnIf-a4f9d411.js";
function Ce() {

@@ -62,3 +62,3 @@ return typeof window != "undefined";

const e = pe(), 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.8.1-beta.6");
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.8.1");
const s = document.createElement("iframe");

@@ -65,0 +65,0 @@ s.id = "moneyhash-headless-sdk", s.src = t.toString(), s.hidden = !0, document.body.appendChild(s), b.messagingService = new Ae({

@@ -1,1 +0,1 @@

(function(d,c){typeof exports=="object"&&typeof module!="undefined"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(d=typeof globalThis!="undefined"?globalThis:d||self,c(d.MoneyHash={}))})(this,function(d){var N,Z,D,ee,T,we,W,be,j,Pe,V,te,B,ve,G,ke,Y,Ee,x,Ae;"use strict";var Ie=Object.defineProperty,Ue=Object.defineProperties;var _e=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable;var Q=(d,c,l)=>c in d?Ie(d,c,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[c]=l,E=(d,c)=>{for(var l in c||(c={}))ge.call(c,l)&&Q(d,l,c[l]);if(K)for(var l of K(c))ye.call(c,l)&&Q(d,l,c[l]);return d},z=(d,c)=>Ue(d,_e(c));var fe=(d,c)=>{var l={};for(var S in d)ge.call(d,S)&&c.indexOf(S)<0&&(l[S]=d[S]);if(d!=null&&K)for(var S of K(d))c.indexOf(S)<0&&ye.call(d,S)&&(l[S]=d[S]);return l};var f=(d,c,l)=>(Q(d,typeof c!="symbol"?c+"":c,l),l),Fe=(d,c,l)=>{if(!c.has(d))throw TypeError("Cannot "+l)};var M=(d,c,l)=>{if(c.has(d))throw TypeError("Cannot add the same private member more than once");c instanceof WeakSet?c.add(d):c.set(d,l)};var A=(d,c,l)=>(Fe(d,c,"access private method"),l);var b=(d,c,l)=>new Promise((S,L)=>{var O=R=>{try{F(l.next(R))}catch(H){L(H)}},w=R=>{try{F(l.throw(R))}catch(H){L(H)}},F=R=>R.done?S(R.value):Promise.resolve(R.value).then(O,w);F((l=l.apply(d,c)).next())});class c{constructor(e){f(this,"target");f(this,"targetOrigin");f(this,"listeners");f(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 l(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function S(){return typeof window!="undefined"}const C=class{constructor(){S()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=l(),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.8.1-beta.6");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),C.messagingService=new c({target:n.contentWindow,targetOrigin:e}),C.isCommunicationReady=new Promise(i=>{var o;const a=r=>{var s;r.data.type==="headlessSDK:init"&&(i(),(s=C.messagingService)==null||s.removeListener(a))};(o=C.messagingService)==null||o.onReceive(a)})}request(n){return b(this,arguments,function*({api:e,payload:t}){return yield C.isCommunicationReady,new Promise((i,a)=>{var r,s;(r=C.messagingService)==null||r.send({type:e,data:t});const o=m=>{var u;const{type:h,data:p}=m.data;h===e&&(p.status==="resolved"?i(p.payload):a(p.payload),(u=C.messagingService)==null||u.removeListener(o))};(s=C.messagingService)==null||s.onReceive(o)})})}postMessage(e){var t;(t=C.messagingService)==null||t.send({type:e})}};let L=C;f(L,"messagingService",null),f(L,"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 w(y,e){if(y)throw new Error(e)}const F=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class H{constructor(e){f(this,"options");f(this,"messagingService",null);f(this,"iframe",null);f(this,"isCommunicationReady",null);w(!F.has(e.type),`MoneyHash constructor must be called with valid type (${[...F].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 a=l(),o=new URL(`${a}/embed/${this.options.type}/${t}`);o.searchParams.set("sdk","true"),o.searchParams.set("parent",window.location.origin),o.searchParams.set("version","js@1.8.1-beta.6"),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 u;O.includes(p)&&((u=this.iframe)==null||u.sandbox.add(p))});const s=document.querySelector(e);return w(!s,`Couldn't find an element with selector ${e}!`),s.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:a}),this.isCommunicationReady=new Promise(p=>{var k;const u=v=>{var P;v.data.type==="sdk:init"&&(p(),(P=this.messagingService)==null||P.removeListener(u))};(k=this.messagingService)==null||k.onReceive(u)}),this.messagingService.onReceive((p,u)=>{var P,U,g,q;const{type:k,data:v}=p.data;switch(k){case"sdk:init":{u({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(U=(P=this.options).onComplete)==null||U.call(P,E({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(q=(g=this.options).onFail)==null||q.call(g,E({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{i==null||i(v.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return b(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 b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class J{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Se(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function $(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function Re(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ie(y){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!y.includes(t))return t;return null}function se(y){return(Array.isArray(y)?y.length:Object.keys(y).length)===0}function ae(y,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=y,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(a)})}function Ce(y){return new Promise(e=>{setTimeout(()=>{e("done")},y*1e3)})}function Me(y,e){y&&console.warn(e)}const ne=new Set(["method","customerBalance","savedCard"]);class Le{constructor(e){M(this,N);M(this,D);M(this,T);M(this,W);M(this,j);M(this,V);M(this,B);M(this,G);M(this,Y);M(this,x);f(this,"options");f(this,"sdkApiHandler",new L);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>b(this,null,function*(){w(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=ie(this.mountedCardElements);w(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,D,ee).call(this,{accessToken:t})}),pay:o=>b(this,[o],function*({intentId:e,cardData:t,saveCard:n,billingData:i,shippingData:a}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:i,shippingData:a,cardEmbed:t,saveCard:n}})}),createCardToken:n=>b(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(z(E({},e),{headless:!0})),A(this,G,ke).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):(w(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),w(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:E({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:i,metaData:a}){return w(!ne.has(t),`type must be a valid one (${[...ne].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:a}})}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 w(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 b(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:i,onCancel:a=()=>{},onError:o,onComplete:r,billingData:s={}}){if(yield ae("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:["email"]}),{state:p,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(se(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(v){throw yield this.resetSelectedMethod(e),v}const k=new J;return h.onvalidatemerchant=v=>{fetch(`${Re()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:v.validationURL})}).then(P=>P.ok?P.json():Promise.reject()).then(P=>h.completeMerchantValidation(P)).catch(o)},h.onpaymentauthorized=v=>{var P;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:v.payment.token}),receiptBillingData:{email:(P=v.payment.shippingContact)==null?void 0:P.emailAddress}}}).then(U=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),k.resolve(U)}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),o==null||o(),k.reject(void 0)})},h.oncancel=a,h.begin(),k.promise})}renderGooglePayButton(n){return b(this,null,function*(){var i=n,{onClick:e}=i,t=fe(i,["onClick"]);var r;const a=document.getElementById("moneyHash-google-pay-button");w(!a,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ae("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=A(this,N,Z).call(this);this.googlePaymentsClient.isReadyToPay(o).then(s=>{if(s.result){const m=this.googlePaymentsClient.createButton(z(E({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));a==null||a.replaceChildren(m)}else throw new Error("Google Pay is not ready to pay!")}).catch(s=>{console.dir(s)})})}payWithGooglePay(i){return b(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){w(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let a=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(a.state==="FORM_FIELDS"){if(se(t))throw new Error("Billing data is missing while calling payWithGooglePay");a=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}=a;return o?this.googlePaymentsClient.loadPaymentData(z(E({},A(this,N,Z).call(this,o)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${o.amount}`,currencyCode:o.currency_code,countryCode:o.country_code},merchantInfo:{merchantName:o==null?void 0:o.merchant_name,merchantId:o==null?void 0:o.merchant_id},emailRequired:!0})).then(r=>{const s=r.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:s,receiptBillingData:{email:r.email}}})}).catch(r=>(r.statusCode==="CANCELED"?n==null||n():console.dir(r),Promise.reject(r))):a})}renderForm(e){return w(!e.selector,"selector is required for renderForm"),w(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){Me(!!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 w(!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=>{w(!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=[],a={},o=new Map;let r=!1;return A(this,B,ve).call(this,i),{create:({elementType:s,elementOptions:m})=>{var P,U;const h=new Map;let p=null;const u=E(E({},t),m.classes),k=((P=u==null?void 0:u.focus)==null?void 0:P.split(" "))||["MoneyHashElement--focus"],v=((U=u==null?void 0:u.error)==null?void 0:U.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(m.selector);w(!g,`Couldn't find an element with selector ${m.selector}!`),g.classList.add("MoneyHashElement"),i.push(q=>{var re,oe,de,ce,le,he,pe,me,ue;const{type:I,data:_}=q.data;if(I===`${s}@mount`&&(a[s]=_.isValid,(re=h.get(`${s}@mount`))==null||re()),I===`${s}@focus`){g.classList.add(...k),(oe=h.get(`${s}@focus`))==null||oe();return}if(I===`${s}@blur`){g.classList.remove(...k),(de=h.get(`${s}@blur`))==null||de();return}if(I===`${s}@error`){_.isValid?g.classList.remove(...v):g.classList.add(...v),(ce=h.get(`${s}@error`))==null||ce(_);return}if(I===`${s}@changeInput`){if((le=h.get(`${s}@changeInput`))==null||le({isValid:_.isValid,length:_.length}),a[s]=_.isValid,o.get("validityChange")){const X=Object.values(a).every(Boolean);X!==r&&((he=o.get("validityChange"))==null||he(X),r=X)}return}if(I===`${s}@cardNumberChange`){(pe=h.get(`${s}@cardNumberChange`))==null||pe(_);return}if(I===`${s}@key:Backspace`){(me=h.get(`${s}@key:Backspace`))==null||me();return}I===`${s}@key:Enter`&&((ue=h.get(`${s}@key:Enter`))==null||ue())}),p=A(this,Y,Ee).call(this,{container:g,elementType:s,elementOptions:m,styles:E(E({},e),m.styles),fontSourceCss:n}),this.mountedCardElements.push(s)},on:(g,q)=>{h.set(`${s}@${g}`,q)},off:g=>h.delete(`${s}@${g}`),focus:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"focus"},$())},blur:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"blur"},$())},clear:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"clear"},$())}}},on:(s,m)=>{o.set(s,m)}}}submitForm(r){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:i,saveCard:a,paymentMethod:o="CARD"}){let s;if(t){const h=ie(this.mountedCardElements);w(!!h,`You must mount ${h} element!`),s=yield A(this,D,ee).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:s,saveCard:a}})})}submitCvv(n){return b(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(a){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:i}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return A(this,T,we).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,W,be).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return A(this,j,Pe).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),i=setInterval(()=>b(this,null,function*(){const a=new Date;n<a&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}N=new WeakSet,Z=function(e){var n,i;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[E({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}}}:{})]}},D=new WeakSet,ee=function(t){return b(this,arguments,function*({accessToken:e}){const n=new J;this.vaultSubmitListener.current=o=>{const{type:r,data:s}=o.data;r==="vaultSubmit:success"&&n.resolve(s),r==="vaultSubmit:error"&&n.reject(s)};const i=A(this,x,Ae).call(this,{accessToken:e}),a=yield n.promise;return i.remove(),a})},T=new WeakSet,we=function(n){return b(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");w(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const a=document.createElement("iframe");a.src=t,a.style.setProperty("border","0","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("height","100%","important"),i==null||i.replaceChildren(a),yield A(this,V,te).call(this,{intentId:e}),a.remove()})},W=new WeakSet,be=function(i){return b(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:a=600,height:o=400,left:r=200,top:s=200}=n.window||{},m=window.open(t,"",`width=${a},height=${o},left=${r},top=${s}`);w(!m,"Popup blocked by browser!"),yield A(this,V,te).call(this,{intentId:e,isUsingPopUp:!0}),m==null||m.close()})},j=new WeakSet,Pe=function(n){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},V=new WeakSet,te=function(n){return b(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new J,a=o=>b(this,null,function*(){var s,m,h,p;if(o.origin!==l())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),Ce(2)]),k=u.transaction.status.split(".")[1];k==="successful"||k.startsWith("pending")?(m=(s=this.options).onComplete)==null||m.call(s,E({type:this.options.type},u)):(p=(h=this.options).onFail)==null||p.call(h,E({type:this.options.type},u)),i.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),i.promise})},B=new WeakSet,ve=function(e){const t=n=>{n.origin===$()&&e.forEach(i=>{i(n)})};window.addEventListener("message",t)},G=new WeakSet,ke=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},Y=new WeakSet,Ee=function({container:e,elementType:t,elementOptions:n,styles:i,fontSourceCss:a}){var m,h,p,u;const o=$(),r=new URL(`${o}/vaultField/vaultField.html`);a&&r.searchParams.set("fontSourceCss",a),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("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=(u=i==null?void 0:i.height)!=null?u:"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,Ae=function({accessToken:e}){const t=$(),n=Se(),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 a=document.createElement("iframe");return a.id="moneyhash-submit-iframe",a.src=i.toString(),a.hidden=!0,document.body.appendChild(a),a},d.IFrameSandboxOptions=O,d.default=Le,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(d,c){typeof exports=="object"&&typeof module!="undefined"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(d=typeof globalThis!="undefined"?globalThis:d||self,c(d.MoneyHash={}))})(this,function(d){var N,Z,D,ee,T,we,W,be,j,Pe,V,te,B,ve,G,ke,Y,Ee,x,Ae;"use strict";var Ie=Object.defineProperty,Ue=Object.defineProperties;var _e=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable;var Q=(d,c,l)=>c in d?Ie(d,c,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[c]=l,E=(d,c)=>{for(var l in c||(c={}))ge.call(c,l)&&Q(d,l,c[l]);if(K)for(var l of K(c))ye.call(c,l)&&Q(d,l,c[l]);return d},z=(d,c)=>Ue(d,_e(c));var fe=(d,c)=>{var l={};for(var S in d)ge.call(d,S)&&c.indexOf(S)<0&&(l[S]=d[S]);if(d!=null&&K)for(var S of K(d))c.indexOf(S)<0&&ye.call(d,S)&&(l[S]=d[S]);return l};var f=(d,c,l)=>(Q(d,typeof c!="symbol"?c+"":c,l),l),Fe=(d,c,l)=>{if(!c.has(d))throw TypeError("Cannot "+l)};var M=(d,c,l)=>{if(c.has(d))throw TypeError("Cannot add the same private member more than once");c instanceof WeakSet?c.add(d):c.set(d,l)};var A=(d,c,l)=>(Fe(d,c,"access private method"),l);var b=(d,c,l)=>new Promise((S,L)=>{var O=R=>{try{F(l.next(R))}catch(H){L(H)}},w=R=>{try{F(l.throw(R))}catch(H){L(H)}},F=R=>R.done?S(R.value):Promise.resolve(R.value).then(O,w);F((l=l.apply(d,c)).next())});class c{constructor(e){f(this,"target");f(this,"targetOrigin");f(this,"listeners");f(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 l(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function S(){return typeof window!="undefined"}const C=class{constructor(){S()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=l(),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.8.1");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),C.messagingService=new c({target:n.contentWindow,targetOrigin:e}),C.isCommunicationReady=new Promise(i=>{var o;const a=r=>{var s;r.data.type==="headlessSDK:init"&&(i(),(s=C.messagingService)==null||s.removeListener(a))};(o=C.messagingService)==null||o.onReceive(a)})}request(n){return b(this,arguments,function*({api:e,payload:t}){return yield C.isCommunicationReady,new Promise((i,a)=>{var r,s;(r=C.messagingService)==null||r.send({type:e,data:t});const o=m=>{var u;const{type:h,data:p}=m.data;h===e&&(p.status==="resolved"?i(p.payload):a(p.payload),(u=C.messagingService)==null||u.removeListener(o))};(s=C.messagingService)==null||s.onReceive(o)})})}postMessage(e){var t;(t=C.messagingService)==null||t.send({type:e})}};let L=C;f(L,"messagingService",null),f(L,"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 w(y,e){if(y)throw new Error(e)}const F=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class H{constructor(e){f(this,"options");f(this,"messagingService",null);f(this,"iframe",null);f(this,"isCommunicationReady",null);w(!F.has(e.type),`MoneyHash constructor must be called with valid type (${[...F].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 a=l(),o=new URL(`${a}/embed/${this.options.type}/${t}`);o.searchParams.set("sdk","true"),o.searchParams.set("parent",window.location.origin),o.searchParams.set("version","js@1.8.1"),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 u;O.includes(p)&&((u=this.iframe)==null||u.sandbox.add(p))});const s=document.querySelector(e);return w(!s,`Couldn't find an element with selector ${e}!`),s.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:a}),this.isCommunicationReady=new Promise(p=>{var k;const u=v=>{var P;v.data.type==="sdk:init"&&(p(),(P=this.messagingService)==null||P.removeListener(u))};(k=this.messagingService)==null||k.onReceive(u)}),this.messagingService.onReceive((p,u)=>{var P,U,g,q;const{type:k,data:v}=p.data;switch(k){case"sdk:init":{u({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(U=(P=this.options).onComplete)==null||U.call(P,E({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(q=(g=this.options).onFail)==null||q.call(g,E({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{i==null||i(v.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return b(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 b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class J{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Se(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function $(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function Re(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ie(y){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!y.includes(t))return t;return null}function se(y){return(Array.isArray(y)?y.length:Object.keys(y).length)===0}function ae(y,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=y,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(a)})}function Ce(y){return new Promise(e=>{setTimeout(()=>{e("done")},y*1e3)})}function Me(y,e){y&&console.warn(e)}const ne=new Set(["method","customerBalance","savedCard"]);class Le{constructor(e){M(this,N);M(this,D);M(this,T);M(this,W);M(this,j);M(this,V);M(this,B);M(this,G);M(this,Y);M(this,x);f(this,"options");f(this,"sdkApiHandler",new L);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>b(this,null,function*(){w(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=ie(this.mountedCardElements);w(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,D,ee).call(this,{accessToken:t})}),pay:o=>b(this,[o],function*({intentId:e,cardData:t,saveCard:n,billingData:i,shippingData:a}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:i,shippingData:a,cardEmbed:t,saveCard:n}})}),createCardToken:n=>b(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(z(E({},e),{headless:!0})),A(this,G,ke).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):(w(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),w(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:E({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:i,metaData:a}){return w(!ne.has(t),`type must be a valid one (${[...ne].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:a}})}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 w(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 b(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:i,onCancel:a=()=>{},onError:o,onComplete:r,billingData:s={}}){if(yield ae("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:["email"]}),{state:p,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(se(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(v){throw yield this.resetSelectedMethod(e),v}const k=new J;return h.onvalidatemerchant=v=>{fetch(`${Re()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:v.validationURL})}).then(P=>P.ok?P.json():Promise.reject()).then(P=>h.completeMerchantValidation(P)).catch(o)},h.onpaymentauthorized=v=>{var P;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:v.payment.token}),receiptBillingData:{email:(P=v.payment.shippingContact)==null?void 0:P.emailAddress}}}).then(U=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),k.resolve(U)}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),o==null||o(),k.reject(void 0)})},h.oncancel=a,h.begin(),k.promise})}renderGooglePayButton(n){return b(this,null,function*(){var i=n,{onClick:e}=i,t=fe(i,["onClick"]);var r;const a=document.getElementById("moneyHash-google-pay-button");w(!a,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ae("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=A(this,N,Z).call(this);this.googlePaymentsClient.isReadyToPay(o).then(s=>{if(s.result){const m=this.googlePaymentsClient.createButton(z(E({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));a==null||a.replaceChildren(m)}else throw new Error("Google Pay is not ready to pay!")}).catch(s=>{console.dir(s)})})}payWithGooglePay(i){return b(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){w(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let a=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(a.state==="FORM_FIELDS"){if(se(t))throw new Error("Billing data is missing while calling payWithGooglePay");a=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}=a;return o?this.googlePaymentsClient.loadPaymentData(z(E({},A(this,N,Z).call(this,o)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${o.amount}`,currencyCode:o.currency_code,countryCode:o.country_code},merchantInfo:{merchantName:o==null?void 0:o.merchant_name,merchantId:o==null?void 0:o.merchant_id},emailRequired:!0})).then(r=>{const s=r.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:s,receiptBillingData:{email:r.email}}})}).catch(r=>(r.statusCode==="CANCELED"?n==null||n():console.dir(r),Promise.reject(r))):a})}renderForm(e){return w(!e.selector,"selector is required for renderForm"),w(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){Me(!!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 w(!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=>{w(!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=[],a={},o=new Map;let r=!1;return A(this,B,ve).call(this,i),{create:({elementType:s,elementOptions:m})=>{var P,U;const h=new Map;let p=null;const u=E(E({},t),m.classes),k=((P=u==null?void 0:u.focus)==null?void 0:P.split(" "))||["MoneyHashElement--focus"],v=((U=u==null?void 0:u.error)==null?void 0:U.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(m.selector);w(!g,`Couldn't find an element with selector ${m.selector}!`),g.classList.add("MoneyHashElement"),i.push(q=>{var re,oe,de,ce,le,he,pe,me,ue;const{type:I,data:_}=q.data;if(I===`${s}@mount`&&(a[s]=_.isValid,(re=h.get(`${s}@mount`))==null||re()),I===`${s}@focus`){g.classList.add(...k),(oe=h.get(`${s}@focus`))==null||oe();return}if(I===`${s}@blur`){g.classList.remove(...k),(de=h.get(`${s}@blur`))==null||de();return}if(I===`${s}@error`){_.isValid?g.classList.remove(...v):g.classList.add(...v),(ce=h.get(`${s}@error`))==null||ce(_);return}if(I===`${s}@changeInput`){if((le=h.get(`${s}@changeInput`))==null||le({isValid:_.isValid,length:_.length}),a[s]=_.isValid,o.get("validityChange")){const X=Object.values(a).every(Boolean);X!==r&&((he=o.get("validityChange"))==null||he(X),r=X)}return}if(I===`${s}@cardNumberChange`){(pe=h.get(`${s}@cardNumberChange`))==null||pe(_);return}if(I===`${s}@key:Backspace`){(me=h.get(`${s}@key:Backspace`))==null||me();return}I===`${s}@key:Enter`&&((ue=h.get(`${s}@key:Enter`))==null||ue())}),p=A(this,Y,Ee).call(this,{container:g,elementType:s,elementOptions:m,styles:E(E({},e),m.styles),fontSourceCss:n}),this.mountedCardElements.push(s)},on:(g,q)=>{h.set(`${s}@${g}`,q)},off:g=>h.delete(`${s}@${g}`),focus:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"focus"},$())},blur:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"blur"},$())},clear:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"clear"},$())}}},on:(s,m)=>{o.set(s,m)}}}submitForm(r){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:i,saveCard:a,paymentMethod:o="CARD"}){let s;if(t){const h=ie(this.mountedCardElements);w(!!h,`You must mount ${h} element!`),s=yield A(this,D,ee).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:s,saveCard:a}})})}submitCvv(n){return b(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(a){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:i}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return A(this,T,we).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,W,be).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return A(this,j,Pe).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),i=setInterval(()=>b(this,null,function*(){const a=new Date;n<a&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}N=new WeakSet,Z=function(e){var n,i;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[E({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}}}:{})]}},D=new WeakSet,ee=function(t){return b(this,arguments,function*({accessToken:e}){const n=new J;this.vaultSubmitListener.current=o=>{const{type:r,data:s}=o.data;r==="vaultSubmit:success"&&n.resolve(s),r==="vaultSubmit:error"&&n.reject(s)};const i=A(this,x,Ae).call(this,{accessToken:e}),a=yield n.promise;return i.remove(),a})},T=new WeakSet,we=function(n){return b(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");w(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const a=document.createElement("iframe");a.src=t,a.style.setProperty("border","0","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("height","100%","important"),i==null||i.replaceChildren(a),yield A(this,V,te).call(this,{intentId:e}),a.remove()})},W=new WeakSet,be=function(i){return b(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:a=600,height:o=400,left:r=200,top:s=200}=n.window||{},m=window.open(t,"",`width=${a},height=${o},left=${r},top=${s}`);w(!m,"Popup blocked by browser!"),yield A(this,V,te).call(this,{intentId:e,isUsingPopUp:!0}),m==null||m.close()})},j=new WeakSet,Pe=function(n){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},V=new WeakSet,te=function(n){return b(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new J,a=o=>b(this,null,function*(){var s,m,h,p;if(o.origin!==l())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),Ce(2)]),k=u.transaction.status.split(".")[1];k==="successful"||k.startsWith("pending")?(m=(s=this.options).onComplete)==null||m.call(s,E({type:this.options.type},u)):(p=(h=this.options).onFail)==null||p.call(h,E({type:this.options.type},u)),i.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),i.promise})},B=new WeakSet,ve=function(e){const t=n=>{n.origin===$()&&e.forEach(i=>{i(n)})};window.addEventListener("message",t)},G=new WeakSet,ke=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},Y=new WeakSet,Ee=function({container:e,elementType:t,elementOptions:n,styles:i,fontSourceCss:a}){var m,h,p,u;const o=$(),r=new URL(`${o}/vaultField/vaultField.html`);a&&r.searchParams.set("fontSourceCss",a),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("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=(u=i==null?void 0:i.height)!=null?u:"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,Ae=function({accessToken:e}){const t=$(),n=Se(),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 a=document.createElement("iframe");return a.id="moneyhash-submit-iframe",a.src=i.toString(),a.hidden=!0,document.body.appendChild(a),a},d.IFrameSandboxOptions=O,d.default=Le,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-d0a82549.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-43195b62.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-bcd4d922.js";
import { S as o, t as d, w as u, s as a } from "./warnIf-a4f9d411.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.8.1-beta.6"),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.8.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});
{
"name": "@moneyhash/js-sdk",
"version": "1.8.1-beta.6",
"version": "1.8.1",
"description": "MoneyHash JavaScript SDK",

@@ -5,0 +5,0 @@ "type": "module",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc