@moneyhash/js-sdk
Advanced tools
Comparing version 1.13.0 to 1.13.1
@@ -1,1 +0,1 @@ | ||
"use strict";var Ie=Object.defineProperty,Se=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var Y=(l,e,t)=>e in l?Ie(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,b=(l,e)=>{for(var t in e||(e={}))de.call(e,t)&&Y(l,t,e[t]);if(q)for(var t of q(e))ce.call(e,t)&&Y(l,t,e[t]);return l},T=(l,e)=>Se(l,Ce(e));var pe=(l,e)=>{var t={};for(var n in l)de.call(l,n)&&e.indexOf(n)<0&&(t[n]=l[n]);if(l!=null&&q)for(var n of q(l))e.indexOf(n)<0&&ce.call(l,n)&&(t[n]=l[n]);return t};var f=(l,e,t)=>(Y(l,typeof e!="symbol"?e+"":e,t),t),ue=(l,e,t)=>{if(!e.has(l))throw TypeError("Cannot "+t)};var H=(l,e,t)=>(ue(l,e,"read from private field"),t?t.call(l):e.get(l)),P=(l,e,t)=>{if(e.has(l))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(l):e.set(l,t)};var w=(l,e,t)=>(ue(l,e,"access private method"),t);var h=(l,e,t)=>new Promise((n,a)=>{var i=s=>{try{r(t.next(s))}catch(d){a(d)}},o=s=>{try{r(t.throw(s))}catch(d){a(d)}},r=s=>s.done?n(s.value):Promise.resolve(s.value).then(i,o);r((t=t.apply(l,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("./warnIf-b7250ca2.cjs");function ve(){return typeof window!="undefined"}const k=class{constructor(){ve()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=c.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.13.0");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),k.messagingService=new c.MessagingService({target:n.contentWindow,targetOrigin:e}),k.isCommunicationReady=new Promise(a=>{var o;const i=r=>{var s;r.data.type==="headlessSDK:init"&&(a(),(s=k.messagingService)==null||s.removeListener(i))};(o=k.messagingService)==null||o.onReceive(i)})}request(n){return h(this,arguments,function*({api:e,payload:t}){return yield k.isCommunicationReady,new Promise((a,i)=>{var r,s;(r=k.messagingService)==null||r.send({type:e,data:t});const o=d=>{var m;const{type:u,data:p}=d.data;u===e&&(p.status==="resolved"?a(p.payload):i(p.payload),(m=k.messagingService)==null||m.removeListener(o))};(s=k.messagingService)==null||s.onReceive(o)})})}postMessage(e){var t;(t=k.messagingService)==null||t.send({type:e})}};let M=k;f(M,"messagingService",null),f(M,"isCommunicationReady");class F{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Me(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function C(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function me(l){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!l.includes(t))return t;return null}function he(l){return(Array.isArray(l)?l.length:Object.keys(l).length)===0}function x(l,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const i=document.createElement("script");i.src=l,i.id=e,i.addEventListener("load",()=>{t(void 0)}),i.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(i)})}function Re(l){return new Promise(e=>{setTimeout(()=>{e("done")},l*1e3)})}const ge=new Set(["method","customerBalance","savedCard"]);var R,z,$,ye,L,J,U,X,N,fe,D,we,V,Pe,_,Q,B,be,O,ke,W,Ae,G,Ee;class Le{constructor(e){P(this,R);P(this,$);P(this,L);P(this,U);P(this,N);P(this,D);P(this,V);P(this,_);P(this,B);P(this,O);P(this,W);P(this,G);f(this,"options");f(this,"sdkApiHandler",new M);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>h(this,null,function*(){c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=me(this.mountedCardElements);c.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return w(this,U,X).call(this,{accessToken:t})}),pay:r=>h(this,[r],function*({intentId:e,cardData:t,saveCard:n,billingData:a,shippingData:i,installmentPlanData:o}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:i,cardEmbed:t,saveCard:n,installmentPlanData:o}})}),createCardToken:n=>h(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}})}),binLookup:n=>h(this,[n],function*({cardData:e,flowId:t}){return this.sdkApiHandler.request({api:"sdk:binLookup",payload:{cardData:e,flowId:t,publicApiKey:this.options.publicApiKey}})})});f(this,"defaultCardHolderName","");this.options=e,this.sdkEmbed=new c.SDKEmbed(T(b({},e),{headless:!0})),w(this,O,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):(c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),c.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:{intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey,operation:e.operation,currency:e.currency,amount:e.amount,customer:e.customer,flowId:e.flowId,custom_fields:e.customFields}}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:a,metaData:i,installmentPlanData:o}){return c.throwIf(!ge.has(t),`type must be a valid one (${[...ge].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:n,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData:i,installmentPlanData:o}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return c.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(d){return h(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:a,onCancel:i=()=>{},onError:o,onComplete:r,billingData:s={}}){if(yield x("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const u=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${n}`},requiredShippingContactFields:H(this,L,J)}),{state:p,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(he(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(A){throw yield this.resetSelectedMethod(e),A}const y=new F;return u.onvalidatemerchant=A=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:m.secret,validationUrl:A.validationURL,parentOrigin:window.location.origin}}).then(I=>u.completeMerchantValidation(I)).catch(o),u.onpaymentauthorized=A=>{var I;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:A.payment.token}),receiptBillingData:{email:(I=A.payment.shippingContact)==null?void 0:I.emailAddress}}}).then(v=>{u.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(v),y.resolve(v)}).catch(()=>{u.completePayment(ApplePaySession.STATUS_FAILURE),o==null||o(),y.reject(void 0)})},u.oncancel=i,u.begin(),y.promise})}renderGooglePayButton(n){return h(this,null,function*(){var a=n,{onClick:e}=a,t=pe(a,["onClick"]);var r;const i=document.getElementById("moneyHash-google-pay-button");c.throwIf(!i,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield x("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=w(this,R,z).call(this);this.googlePaymentsClient.isReadyToPay(o).then(s=>{if(s.result){const d=this.googlePaymentsClient.createButton(T(b({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));i==null||i.replaceChildren(d)}else throw new Error("Google Pay is not ready to pay!")}).catch(s=>{console.dir(s)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t}){return c.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),c.throwIf(!e,"nativePayData is required to generate Google Pay receipt!"),c.throwIf(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(T(b({},w(this,R,z).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:H(this,$,ye).includes("email")})).then(n=>({receipt:n.paymentMethodData.tokenizationData.token,receiptBillingData:{email:n.email}})).catch(n=>(n.statusCode==="CANCELED"?t==null||t():console.dir(n),Promise.reject(n)))}generateApplePayReceipt(n){return h(this,arguments,function*({nativePayData:e,onCancel:t=()=>{}}){if(yield x("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),c.throwIf(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(c.throwIf(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const a=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:H(this,L,J)}),i=new F;return a.onvalidatemerchant=o=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:o.validationURL,parentOrigin:window.location.origin}}).then(r=>a.completeMerchantValidation(r)).catch(r=>{a.abort(),i.reject(r)}),a.onpaymentauthorized=o=>{var s;const r={receipt:JSON.stringify({token:o.payment.token}),receiptBillingData:{email:(s=o.payment.shippingContact)==null?void 0:s.emailAddress}};a.completePayment(ApplePaySession.STATUS_SUCCESS),i.resolve(r)},a.oncancel=t,a.begin(),i.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(a){return h(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){c.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let i=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(i.state==="FORM_FIELDS"){if(he(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(r){throw yield this.resetSelectedMethod(e),r}const{nativePayData:o}=i;return o?this.generateGooglePayReceipt({nativePayData:o,onCancel:n}).then(r=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:r})):i})}renderForm(e){return c.throwIf(!e.selector,"selector is required for renderForm"),c.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){c.warnIf(!!e&&!c.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...c.supportedLanguages].join(" | ")})`);const t=c.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return c.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(n=>{c.throwIf(!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 a=[],i={},o=new Map;let r=!1;return w(this,B,be).call(this,a),{create:s=>{var v,Z;if("value"in s)return c.throwIf(s.elementType!=="cardHolderName",`Value is not allowed! for ${s.elementType}`),this.defaultCardHolderName=s.value,{mount:()=>{},on:()=>{},off:()=>!0,focus:()=>{},blur:()=>{},clear:()=>{this.defaultCardHolderName=""}};const{elementType:d,elementOptions:u}=s,p=new Map;let m=null;const y=b(b({},t),u.classes),A=((v=y==null?void 0:y.focus)==null?void 0:v.split(" "))||["MoneyHashElement--focus"],I=((Z=y==null?void 0:y.error)==null?void 0:Z.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(u.selector);c.throwIf(!g,`Couldn't find an element with selector ${u.selector}!`),g.classList.add("MoneyHashElement"),a.push(j=>{var ee,te,ae,ne,ie,re,se,oe,le;const{type:E,data:S}=j.data;if(E===`${d}@mount`&&(i[d]=S.isValid,(ee=p.get(`${d}@mount`))==null||ee()),E===`${d}@focus`){g.classList.add(...A),(te=p.get(`${d}@focus`))==null||te();return}if(E===`${d}@blur`){g.classList.remove(...A),(ae=p.get(`${d}@blur`))==null||ae();return}if(E===`${d}@error`){S.isValid?g.classList.remove(...I):g.classList.add(...I),(ne=p.get(`${d}@error`))==null||ne(S);return}if(E===`${d}@changeInput`){if((ie=p.get(`${d}@changeInput`))==null||ie({isValid:S.isValid,length:S.length}),i[d]=S.isValid,o.get("validityChange")){const K=Object.values(i).every(Boolean);K!==r&&((re=o.get("validityChange"))==null||re(K),r=K)}return}if(E===`${d}@cardNumberChange`){(se=p.get(`${d}@cardNumberChange`))==null||se(S);return}if(E===`${d}@key:Backspace`){(oe=p.get(`${d}@key:Backspace`))==null||oe();return}E===`${d}@key:Enter`&&((le=p.get(`${d}@key:Enter`))==null||le())}),m=w(this,W,Ae).call(this,{container:g,elementType:d,elementOptions:u,styles:b(b({},e),u.styles),fontSourceCss:n}),this.mountedCardElements.push(d)},on:(g,j)=>{p.set(`${d}@${g}`,j)},off:g=>p.delete(`${d}@${g}`),focus:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"focus"},C())},blur:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"blur"},C())},clear:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"clear"},C())}}},on:(s,d)=>{o.set(s,d)},off(s){o.delete(s)}}}submitForm(s){return h(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:a,saveCard:i,paymentMethod:o="CARD",installmentPlanData:r}){let d;if(t){const p=me(this.mountedCardElements);c.throwIf(!!p,`You must mount ${p} element!`),d=yield w(this,U,X).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:n,shippingData:a,cardEmbed:d,saveCard:i,installmentPlanData:r}})})}selectInstallmentPlan(a){return h(this,arguments,function*({intentId:e,planId:t,issuerCode:n}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:n,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(a){return h(this,arguments,function*({first6Digits:e,amount:t,currency:n}){return c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:n,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(a){return h(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:n}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:n,lang:this.sdkEmbed.lang}})})}renderUrl(i){return h(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return w(this,N,fe).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return w(this,D,we).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return w(this,V,Pe).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),a=setInterval(()=>h(this,null,function*(){const i=new Date;n<i&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}R=new WeakSet,z=function(e){var n,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[b({type:"CARD",parameters:{allowedAuthMethods:((n=this.options.googlePay)==null?void 0:n.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}}}:{})]}},$=new WeakSet,ye=function(){var e;return((e=this.options.googlePay)==null?void 0:e.collectibleBillingData)||["email"]},L=new WeakSet,J=function(){var e;return((e=this.options.applePay)==null?void 0:e.collectibleBillingData)||["email"]},U=new WeakSet,X=function(t){return h(this,arguments,function*({accessToken:e}){const n=new F;this.vaultSubmitListener.current=o=>{const{type:r,data:s}=o.data;r==="vaultSubmit:success"&&n.resolve(s),r==="vaultSubmit:error"&&n.reject(s)};const a=w(this,G,Ee).call(this,{accessToken:e,defaultCardHolderName:this.defaultCardHolderName}),i=yield n.promise;return a.remove(),i})},N=new WeakSet,fe=function(n){return h(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");c.throwIf(!a,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const i=document.createElement("iframe");i.src=t,i.style.setProperty("border","0","important"),i.style.setProperty("width","100%","important"),i.style.setProperty("height","100%","important"),a==null||a.replaceChildren(i),yield w(this,_,Q).call(this,{intentId:e}),i.remove()})},D=new WeakSet,we=function(a){return h(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:i=600,height:o=400,left:r=200,top:s=200}=n.window||{},d=window.open(t,"",`width=${i},height=${o},left=${r},top=${s}`);c.throwIf(!d,"Popup blocked by browser!"),yield w(this,_,Q).call(this,{intentId:e,isUsingPopUp:!0}),d==null||d.close()})},V=new WeakSet,Pe=function(n){return h(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},_=new WeakSet,Q=function(n){return h(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new F,i=o=>h(this,null,function*(){var s,d,u,p;if(o.origin!==c.getIframeUrl())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),Re(2)]),y=m.transaction.status.split(".")[1];y==="successful"||y.startsWith("pending")?(d=(s=this.options).onComplete)==null||d.call(s,b({type:this.options.type},m)):(p=(u=this.options).onFail)==null||p.call(u,b({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",i)}});return window.addEventListener("message",i),a.promise})},B=new WeakSet,be=function(e){const t=n=>{n.origin===C()&&e.forEach(a=>{a(n)})};window.addEventListener("message",t)},O=new WeakSet,ke=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},W=new WeakSet,Ae=function({container:e,elementType:t,elementOptions:n,styles:a,fontSourceCss:i}){var d,u,p,m,y;const o=C(),r=new URL(`${o}/vaultField/vaultField.html`);i&&r.searchParams.set("fontSourceCss",i),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((d=n.validation)==null?void 0:d.required)!==void 0&&r.searchParams.set("required",`${(u=n.validation)==null?void 0:u.required}`),r.searchParams.set("placeholder",(p=n.placeholder)!=null?p:""),r.searchParams.set("inputMode",(m=n.inputMode)!=null?m:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(a==null?void 0:a.direction)||""),r.searchParams.set("color",JSON.stringify(a!=null&&a.color?a.color:"#000")),r.searchParams.set("placeholderColor",(a==null?void 0:a.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(a==null?void 0:a.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(a==null?void 0:a.fontSize)||""),r.searchParams.set("fontFamily",(a==null?void 0:a.fontFamily)||""),r.searchParams.set("fontWeight",`${a==null?void 0:a.fontWeight}`),r.searchParams.set("fontStyle",(a==null?void 0:a.fontStyle)||""),r.searchParams.set("padding",(a==null?void 0:a.padding)||"");const s=document.createElement("iframe");return s.src=r.toString(),s.style.height=(y=a==null?void 0:a.height)!=null?y:"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},G=new WeakSet,Ee=function({accessToken:e,defaultCardHolderName:t}){const n=C(),a=Me(),i=new URL(`${n}/vaultSubmit/vaultSubmit.html`);i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("vault_api_url",`${a}/api/v1/tokens/`),i.searchParams.set("access_token",e),i.searchParams.set("lang",this.sdkEmbed.lang),t&&i.searchParams.set("default_card_holder_name",t);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=i.toString(),o.hidden=!0,document.body.appendChild(o),o};exports.IFrameSandboxOptions=c.IFrameSandboxOptions;exports.default=Le; | ||
"use strict";var Ie=Object.defineProperty,Se=Object.defineProperties;var Ce=Object.getOwnPropertyDescriptors;var q=Object.getOwnPropertySymbols;var de=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var Y=(l,e,t)=>e in l?Ie(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,b=(l,e)=>{for(var t in e||(e={}))de.call(e,t)&&Y(l,t,e[t]);if(q)for(var t of q(e))ce.call(e,t)&&Y(l,t,e[t]);return l},T=(l,e)=>Se(l,Ce(e));var pe=(l,e)=>{var t={};for(var n in l)de.call(l,n)&&e.indexOf(n)<0&&(t[n]=l[n]);if(l!=null&&q)for(var n of q(l))e.indexOf(n)<0&&ce.call(l,n)&&(t[n]=l[n]);return t};var f=(l,e,t)=>(Y(l,typeof e!="symbol"?e+"":e,t),t),ue=(l,e,t)=>{if(!e.has(l))throw TypeError("Cannot "+t)};var H=(l,e,t)=>(ue(l,e,"read from private field"),t?t.call(l):e.get(l)),P=(l,e,t)=>{if(e.has(l))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(l):e.set(l,t)};var w=(l,e,t)=>(ue(l,e,"access private method"),t);var h=(l,e,t)=>new Promise((n,a)=>{var i=s=>{try{r(t.next(s))}catch(d){a(d)}},o=s=>{try{r(t.throw(s))}catch(d){a(d)}},r=s=>s.done?n(s.value):Promise.resolve(s.value).then(i,o);r((t=t.apply(l,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("./warnIf-b0d52042.cjs");function ve(){return typeof window!="undefined"}const k=class{constructor(){ve()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=c.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.13.1");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),k.messagingService=new c.MessagingService({target:n.contentWindow,targetOrigin:e}),k.isCommunicationReady=new Promise(a=>{var o;const i=r=>{var s;r.data.type==="headlessSDK:init"&&(a(),(s=k.messagingService)==null||s.removeListener(i))};(o=k.messagingService)==null||o.onReceive(i)})}request(n){return h(this,arguments,function*({api:e,payload:t}){return yield k.isCommunicationReady,new Promise((a,i)=>{var r,s;(r=k.messagingService)==null||r.send({type:e,data:t});const o=d=>{var m;const{type:u,data:p}=d.data;u===e&&(p.status==="resolved"?a(p.payload):i(p.payload),(m=k.messagingService)==null||m.removeListener(o))};(s=k.messagingService)==null||s.onReceive(o)})})}postMessage(e){var t;(t=k.messagingService)==null||t.send({type:e})}};let M=k;f(M,"messagingService",null),f(M,"isCommunicationReady");class F{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Me(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function C(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function me(l){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!l.includes(t))return t;return null}function he(l){return(Array.isArray(l)?l.length:Object.keys(l).length)===0}function x(l,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const i=document.createElement("script");i.src=l,i.id=e,i.addEventListener("load",()=>{t(void 0)}),i.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(i)})}function Re(l){return new Promise(e=>{setTimeout(()=>{e("done")},l*1e3)})}const ge=new Set(["method","customerBalance","savedCard"]);var R,z,$,ye,L,J,U,X,N,fe,D,we,V,Pe,_,Q,B,be,O,ke,W,Ae,G,Ee;class Le{constructor(e){P(this,R);P(this,$);P(this,L);P(this,U);P(this,N);P(this,D);P(this,V);P(this,_);P(this,B);P(this,O);P(this,W);P(this,G);f(this,"options");f(this,"sdkApiHandler",new M);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>h(this,null,function*(){c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=me(this.mountedCardElements);c.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return w(this,U,X).call(this,{accessToken:t})}),pay:r=>h(this,[r],function*({intentId:e,cardData:t,saveCard:n,billingData:a,shippingData:i,installmentPlanData:o}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:i,cardEmbed:t,saveCard:n,installmentPlanData:o}})}),createCardToken:n=>h(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}})}),binLookup:n=>h(this,[n],function*({cardData:e,flowId:t}){return this.sdkApiHandler.request({api:"sdk:binLookup",payload:{cardData:e,flowId:t,publicApiKey:this.options.publicApiKey}})})});f(this,"defaultCardHolderName","");this.options=e,this.sdkEmbed=new c.SDKEmbed(T(b({},e),{headless:!0})),w(this,O,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):(c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),c.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:{intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey,operation:e.operation,currency:e.currency,amount:e.amount,customer:e.customer,flowId:e.flowId,custom_fields:e.customFields}}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:a,metaData:i,installmentPlanData:o}){return c.throwIf(!ge.has(t),`type must be a valid one (${[...ge].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:n,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData:i,installmentPlanData:o}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return c.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(d){return h(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:a,onCancel:i=()=>{},onError:o,onComplete:r,billingData:s={}}){if(yield x("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const u=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${n}`},requiredShippingContactFields:H(this,L,J)}),{state:p,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(he(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(A){throw yield this.resetSelectedMethod(e),A}const y=new F;return u.onvalidatemerchant=A=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:m.secret,validationUrl:A.validationURL,parentOrigin:window.location.origin}}).then(I=>u.completeMerchantValidation(I)).catch(o),u.onpaymentauthorized=A=>{var I;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:A.payment.token}),receiptBillingData:{email:(I=A.payment.shippingContact)==null?void 0:I.emailAddress}}}).then(v=>{u.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(v),y.resolve(v)}).catch(()=>{u.completePayment(ApplePaySession.STATUS_FAILURE),o==null||o(),y.reject(void 0)})},u.oncancel=i,u.begin(),y.promise})}renderGooglePayButton(n){return h(this,null,function*(){var a=n,{onClick:e}=a,t=pe(a,["onClick"]);var r;const i=document.getElementById("moneyHash-google-pay-button");c.throwIf(!i,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield x("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=w(this,R,z).call(this);this.googlePaymentsClient.isReadyToPay(o).then(s=>{if(s.result){const d=this.googlePaymentsClient.createButton(T(b({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));i==null||i.replaceChildren(d)}else throw new Error("Google Pay is not ready to pay!")}).catch(s=>{console.dir(s)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t}){return c.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),c.throwIf(!e,"nativePayData is required to generate Google Pay receipt!"),c.throwIf(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(T(b({},w(this,R,z).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:H(this,$,ye).includes("email")})).then(n=>({receipt:n.paymentMethodData.tokenizationData.token,receiptBillingData:{email:n.email}})).catch(n=>(n.statusCode==="CANCELED"?t==null||t():console.dir(n),Promise.reject(n)))}generateApplePayReceipt(n){return h(this,arguments,function*({nativePayData:e,onCancel:t=()=>{}}){if(yield x("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),c.throwIf(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(c.throwIf(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const a=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:H(this,L,J)}),i=new F;return a.onvalidatemerchant=o=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:o.validationURL,parentOrigin:window.location.origin}}).then(r=>a.completeMerchantValidation(r)).catch(r=>{a.abort(),i.reject(r)}),a.onpaymentauthorized=o=>{var s;const r={receipt:JSON.stringify({token:o.payment.token}),receiptBillingData:{email:(s=o.payment.shippingContact)==null?void 0:s.emailAddress}};a.completePayment(ApplePaySession.STATUS_SUCCESS),i.resolve(r)},a.oncancel=t,a.begin(),i.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(a){return h(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){c.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let i=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(i.state==="FORM_FIELDS"){if(he(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(r){throw yield this.resetSelectedMethod(e),r}const{nativePayData:o}=i;return o?this.generateGooglePayReceipt({nativePayData:o,onCancel:n}).then(r=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:r})):i})}renderForm(e){return c.throwIf(!e.selector,"selector is required for renderForm"),c.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){c.warnIf(!!e&&!c.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...c.supportedLanguages].join(" | ")})`);const t=c.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return c.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(n=>{c.throwIf(!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 a=[],i={},o=new Map;let r=!1;return w(this,B,be).call(this,a),{create:s=>{var v,Z;if("value"in s)return c.throwIf(s.elementType!=="cardHolderName",`Value is not allowed! for ${s.elementType}`),this.defaultCardHolderName=s.value,{mount:()=>{},on:()=>{},off:()=>!0,focus:()=>{},blur:()=>{},clear:()=>{this.defaultCardHolderName=""}};const{elementType:d,elementOptions:u}=s,p=new Map;let m=null;const y=b(b({},t),u.classes),A=((v=y==null?void 0:y.focus)==null?void 0:v.split(" "))||["MoneyHashElement--focus"],I=((Z=y==null?void 0:y.error)==null?void 0:Z.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(u.selector);c.throwIf(!g,`Couldn't find an element with selector ${u.selector}!`),g.classList.add("MoneyHashElement"),a.push(j=>{var ee,te,ae,ne,ie,re,se,oe,le;const{type:E,data:S}=j.data;if(E===`${d}@mount`&&(i[d]=S.isValid,(ee=p.get(`${d}@mount`))==null||ee()),E===`${d}@focus`){g.classList.add(...A),(te=p.get(`${d}@focus`))==null||te();return}if(E===`${d}@blur`){g.classList.remove(...A),(ae=p.get(`${d}@blur`))==null||ae();return}if(E===`${d}@error`){S.isValid?g.classList.remove(...I):g.classList.add(...I),(ne=p.get(`${d}@error`))==null||ne(S);return}if(E===`${d}@changeInput`){if((ie=p.get(`${d}@changeInput`))==null||ie({isValid:S.isValid,length:S.length}),i[d]=S.isValid,o.get("validityChange")){const K=Object.values(i).every(Boolean);K!==r&&((re=o.get("validityChange"))==null||re(K),r=K)}return}if(E===`${d}@cardNumberChange`){(se=p.get(`${d}@cardNumberChange`))==null||se(S);return}if(E===`${d}@key:Backspace`){(oe=p.get(`${d}@key:Backspace`))==null||oe();return}E===`${d}@key:Enter`&&((le=p.get(`${d}@key:Enter`))==null||le())}),m=w(this,W,Ae).call(this,{container:g,elementType:d,elementOptions:u,styles:b(b({},e),u.styles),fontSourceCss:n}),this.mountedCardElements.push(d)},on:(g,j)=>{p.set(`${d}@${g}`,j)},off:g=>p.delete(`${d}@${g}`),focus:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"focus"},C())},blur:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"blur"},C())},clear:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"clear"},C())}}},on:(s,d)=>{o.set(s,d)},off(s){o.delete(s)}}}submitForm(s){return h(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:a,saveCard:i,paymentMethod:o="CARD",installmentPlanData:r}){let d;if(t){const p=me(this.mountedCardElements);c.throwIf(!!p,`You must mount ${p} element!`),d=yield w(this,U,X).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:n,shippingData:a,cardEmbed:d,saveCard:i,installmentPlanData:r}})})}selectInstallmentPlan(a){return h(this,arguments,function*({intentId:e,planId:t,issuerCode:n}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:n,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(a){return h(this,arguments,function*({first6Digits:e,amount:t,currency:n}){return c.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:n,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(a){return h(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:n}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:n,lang:this.sdkEmbed.lang}})})}renderUrl(i){return h(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return w(this,N,fe).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return w(this,D,we).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return w(this,V,Pe).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),a=setInterval(()=>h(this,null,function*(){const i=new Date;n<i&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}R=new WeakSet,z=function(e){var n,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[b({type:"CARD",parameters:{allowedAuthMethods:((n=this.options.googlePay)==null?void 0:n.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}}}:{})]}},$=new WeakSet,ye=function(){var e;return((e=this.options.googlePay)==null?void 0:e.collectibleBillingData)||["email"]},L=new WeakSet,J=function(){var e;return((e=this.options.applePay)==null?void 0:e.collectibleBillingData)||["email"]},U=new WeakSet,X=function(t){return h(this,arguments,function*({accessToken:e}){const n=new F;this.vaultSubmitListener.current=o=>{const{type:r,data:s}=o.data;r==="vaultSubmit:success"&&n.resolve(s),r==="vaultSubmit:error"&&n.reject(s)};const a=w(this,G,Ee).call(this,{accessToken:e,defaultCardHolderName:this.defaultCardHolderName}),i=yield n.promise;return a.remove(),i})},N=new WeakSet,fe=function(n){return h(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");c.throwIf(!a,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const i=document.createElement("iframe");i.src=t,i.style.setProperty("border","0","important"),i.style.setProperty("width","100%","important"),i.style.setProperty("height","100%","important"),a==null||a.replaceChildren(i),yield w(this,_,Q).call(this,{intentId:e}),i.remove()})},D=new WeakSet,we=function(a){return h(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:i=600,height:o=400,left:r=200,top:s=200}=n.window||{},d=window.open(t,"",`width=${i},height=${o},left=${r},top=${s}`);c.throwIf(!d,"Popup blocked by browser!"),yield w(this,_,Q).call(this,{intentId:e,isUsingPopUp:!0}),d==null||d.close()})},V=new WeakSet,Pe=function(n){return h(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},_=new WeakSet,Q=function(n){return h(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new F,i=o=>h(this,null,function*(){var s,d,u,p;if(o.origin!==c.getIframeUrl())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),Re(2)]),y=m.transaction.status.split(".")[1];y==="successful"||y.startsWith("pending")?(d=(s=this.options).onComplete)==null||d.call(s,b({type:this.options.type},m)):(p=(u=this.options).onFail)==null||p.call(u,b({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",i)}});return window.addEventListener("message",i),a.promise})},B=new WeakSet,be=function(e){const t=n=>{n.origin===C()&&e.forEach(a=>{a(n)})};window.addEventListener("message",t)},O=new WeakSet,ke=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},W=new WeakSet,Ae=function({container:e,elementType:t,elementOptions:n,styles:a,fontSourceCss:i}){var d,u,p,m,y;const o=C(),r=new URL(`${o}/vaultField/vaultField.html`);i&&r.searchParams.set("fontSourceCss",i),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((d=n.validation)==null?void 0:d.required)!==void 0&&r.searchParams.set("required",`${(u=n.validation)==null?void 0:u.required}`),r.searchParams.set("placeholder",(p=n.placeholder)!=null?p:""),r.searchParams.set("inputMode",(m=n.inputMode)!=null?m:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(a==null?void 0:a.direction)||""),r.searchParams.set("color",JSON.stringify(a!=null&&a.color?a.color:"#000")),r.searchParams.set("placeholderColor",(a==null?void 0:a.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(a==null?void 0:a.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(a==null?void 0:a.fontSize)||""),r.searchParams.set("fontFamily",(a==null?void 0:a.fontFamily)||""),r.searchParams.set("fontWeight",`${a==null?void 0:a.fontWeight}`),r.searchParams.set("fontStyle",(a==null?void 0:a.fontStyle)||""),r.searchParams.set("padding",(a==null?void 0:a.padding)||"");const s=document.createElement("iframe");return s.src=r.toString(),s.style.height=(y=a==null?void 0:a.height)!=null?y:"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},G=new WeakSet,Ee=function({accessToken:e,defaultCardHolderName:t}){const n=C(),a=Me(),i=new URL(`${n}/vaultSubmit/vaultSubmit.html`);i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("vault_api_url",`${a}/api/v1/tokens/`),i.searchParams.set("access_token",e),i.searchParams.set("lang",this.sdkEmbed.lang),t&&i.searchParams.set("default_card_holder_name",t);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=i.toString(),o.hidden=!0,document.body.appendChild(o),o};exports.IFrameSandboxOptions=c.IFrameSandboxOptions;exports.default=Le; |
@@ -55,2 +55,3 @@ export declare interface AbstractIntent { | ||
issuerCountryCode: string | null; | ||
product: string | null; | ||
}; | ||
@@ -57,0 +58,0 @@ |
@@ -48,4 +48,4 @@ var ve = Object.defineProperty, Ie = Object.defineProperties; | ||
}); | ||
import { M as Re, g as fe, S as Le, t as p, w as Ue, s as x } from "./warnIf-833ad597.js"; | ||
import { I as Be } from "./warnIf-833ad597.js"; | ||
import { M as Re, g as fe, S as Le, t as p, w as Ue, s as x } from "./warnIf-f9d184c7.js"; | ||
import { I as Be } from "./warnIf-f9d184c7.js"; | ||
function _e() { | ||
@@ -62,3 +62,3 @@ return typeof window != "undefined"; | ||
const e = fe(), 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.13.0"); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.13.1"); | ||
const n = document.createElement("iframe"); | ||
@@ -65,0 +65,0 @@ n.id = "moneyhash-headless-sdk", n.src = t.toString(), n.hidden = !0, document.body.appendChild(n), k.messagingService = new Re({ |
@@ -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 H,ne,W,Ee,$,se,N,re,j,Se,G,Ce,K,Re,D,oe,Y,Me,x,Ie,z,Le,J,Ue;"use strict";var He=Object.defineProperty,$e=Object.defineProperties;var Ne=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var Pe=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var ae=(d,c,p)=>c in d?He(d,c,{enumerable:!0,configurable:!0,writable:!0,value:p}):d[c]=p,S=(d,c)=>{for(var p in c||(c={}))Pe.call(c,p)&&ae(d,p,c[p]);if(X)for(var p of X(c))ke.call(c,p)&&ae(d,p,c[p]);return d},Q=(d,c)=>$e(d,Ne(c));var Ae=(d,c)=>{var p={};for(var v in d)Pe.call(d,v)&&c.indexOf(v)<0&&(p[v]=d[v]);if(d!=null&&X)for(var v of X(d))c.indexOf(v)<0&&ke.call(d,v)&&(p[v]=d[v]);return p};var w=(d,c,p)=>(ae(d,typeof c!="symbol"?c+"":c,p),p),ve=(d,c,p)=>{if(!c.has(d))throw TypeError("Cannot "+p)};var Z=(d,c,p)=>(ve(d,c,"read from private field"),p?p.call(d):c.get(d)),C=(d,c,p)=>{if(c.has(d))throw TypeError("Cannot add the same private member more than once");c instanceof WeakSet?c.add(d):c.set(d,p)};var A=(d,c,p)=>(ve(d,c,"access private method"),p);var y=(d,c,p)=>new Promise((v,I)=>{var V=R=>{try{T(p.next(R))}catch(F){I(F)}},h=R=>{try{T(p.throw(R))}catch(F){I(F)}},T=R=>R.done?v(R.value):Promise.resolve(R.value).then(V,h);T((p=p.apply(d,c)).next())});class c{constructor(e){w(this,"target");w(this,"targetOrigin");w(this,"listeners");w(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function p(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function v(){return typeof window!="undefined"}const M=class{constructor(){v()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=p(),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.13.0");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),M.messagingService=new c({target:n.contentWindow,targetOrigin:e}),M.isCommunicationReady=new Promise(i=>{var s;const a=r=>{var o;r.data.type==="headlessSDK:init"&&(i(),(o=M.messagingService)==null||o.removeListener(a))};(s=M.messagingService)==null||s.onReceive(a)})}request(n){return y(this,arguments,function*({api:e,payload:t}){return yield M.isCommunicationReady,new Promise((i,a)=>{var r,o;(r=M.messagingService)==null||r.send({type:e,data:t});const s=l=>{var u;const{type:g,data:m}=l.data;g===e&&(m.status==="resolved"?i(m.payload):a(m.payload),(u=M.messagingService)==null||u.removeListener(s))};(o=M.messagingService)==null||o.onReceive(s)})})}postMessage(e){var t;(t=M.messagingService)==null||t.send({type:e})}};let I=M;w(I,"messagingService",null),w(I,"isCommunicationReady");const V=["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 h(P,e){if(P)throw new Error(e)}const T=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class F{constructor(e){w(this,"options");w(this,"messagingService",null);w(this,"iframe",null);w(this,"isCommunicationReady",null);h(!T.has(e.type),`MoneyHash constructor must be called with valid type (${[...T].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 l,g;(l=this.messagingService)==null||l.abortService();const a=p(),s=new URL(`${a}/embed/${this.options.type}/${t}`);s.searchParams.set("sdk","true"),s.searchParams.set("parent",window.location.origin),s.searchParams.set("version","js@1.13.0"),i&&s.searchParams.set("onDimensionsChange","true");const r=(g=this.options.locale)==null?void 0:g.split("-")[0];r&&s.searchParams.set("lang",r),this.iframe=document.createElement("iframe"),this.iframe.src=s.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",n&&n.forEach(m=>{var u;V.includes(m)&&((u=this.iframe)==null||u.sandbox.add(m))});const o=document.querySelector(e);return h(!o,`Couldn't find an element with selector ${e}!`),o.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:a}),this.isCommunicationReady=new Promise(m=>{var b;const u=k=>{var E;k.data.type==="sdk:init"&&(m(),(E=this.messagingService)==null||E.removeListener(u))};(b=this.messagingService)==null||b.onReceive(u)}),this.messagingService.onReceive((m,u)=>{var E,L,O,f;const{type:b,data:k}=m.data;switch(b){case"sdk:init":{u({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(L=(E=this.options).onComplete)==null||L.call(E,S({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(f=(O=this.options).onFail)==null||f.call(O,S({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{i==null||i(k.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return y(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 y(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class B{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function _e(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function q(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function le(P){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!P.includes(t))return t;return null}function de(P){return(Array.isArray(P)?P.length:Object.keys(P).length)===0}function ee(P,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=P,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(a)})}function Te(P){return new Promise(e=>{setTimeout(()=>{e("done")},P*1e3)})}function qe(P,e){P&&console.warn(e)}const ce=new Set(["method","customerBalance","savedCard"]);class Fe{constructor(e){C(this,H);C(this,W);C(this,$);C(this,N);C(this,j);C(this,G);C(this,K);C(this,D);C(this,Y);C(this,x);C(this,z);C(this,J);w(this,"options");w(this,"sdkApiHandler",new I);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);w(this,"googlePaymentsClient",null);w(this,"cardForm",{collect:()=>y(this,null,function*(){h(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=le(this.mountedCardElements);h(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,N,re).call(this,{accessToken:t})}),pay:r=>y(this,[r],function*({intentId:e,cardData:t,saveCard:n,billingData:i,shippingData:a,installmentPlanData:s}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:i,shippingData:a,cardEmbed:t,saveCard:n,installmentPlanData:s}})}),createCardToken:n=>y(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}})}),binLookup:n=>y(this,[n],function*({cardData:e,flowId:t}){return this.sdkApiHandler.request({api:"sdk:binLookup",payload:{cardData:e,flowId:t,publicApiKey:this.options.publicApiKey}})})});w(this,"defaultCardHolderName","");this.options=e,this.sdkEmbed=new F(Q(S({},e),{headless:!0})),A(this,x,Ie).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(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),h(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:{intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey,operation:e.operation,currency:e.currency,amount:e.amount,customer:e.customer,flowId:e.flowId,custom_fields:e.customFields}}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:i,metaData:a,installmentPlanData:s}){return h(!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:n,lang:this.sdkEmbed.lang,useWalletBalance:i,metaData:a,installmentPlanData:s}})}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(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 y(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:i,onCancel:a=()=>{},onError:s,onComplete:r,billingData:o={}}){if(yield ee("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const g=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${n}`},requiredShippingContactFields:Z(this,$,se)}),{state:m,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="FORM_FIELDS"){if(de(o))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:o}})}}catch(k){throw yield this.resetSelectedMethod(e),k}const b=new B;return g.onvalidatemerchant=k=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:u.secret,validationUrl:k.validationURL,parentOrigin:window.location.origin}}).then(E=>g.completeMerchantValidation(E)).catch(s),g.onpaymentauthorized=k=>{var E;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:k.payment.token}),receiptBillingData:{email:(E=k.payment.shippingContact)==null?void 0:E.emailAddress}}}).then(L=>{g.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(L),b.resolve(L)}).catch(()=>{g.completePayment(ApplePaySession.STATUS_FAILURE),s==null||s(),b.reject(void 0)})},g.oncancel=a,g.begin(),b.promise})}renderGooglePayButton(n){return y(this,null,function*(){var i=n,{onClick:e}=i,t=Ae(i,["onClick"]);var r;const a=document.getElementById("moneyHash-google-pay-button");h(!a,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ee("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const s=A(this,H,ne).call(this);this.googlePaymentsClient.isReadyToPay(s).then(o=>{if(o.result){const l=this.googlePaymentsClient.createButton(Q(S({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:s.allowedPaymentMethods,onClick:e}));a==null||a.replaceChildren(l)}else throw new Error("Google Pay is not ready to pay!")}).catch(o=>{console.dir(o)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t}){return h(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),h(!e,"nativePayData is required to generate Google Pay receipt!"),h(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(Q(S({},A(this,H,ne).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:Z(this,W,Ee).includes("email")})).then(n=>({receipt:n.paymentMethodData.tokenizationData.token,receiptBillingData:{email:n.email}})).catch(n=>(n.statusCode==="CANCELED"?t==null||t():console.dir(n),Promise.reject(n)))}generateApplePayReceipt(n){return y(this,arguments,function*({nativePayData:e,onCancel:t=()=>{}}){if(yield ee("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),h(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(h(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const i=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:Z(this,$,se)}),a=new B;return i.onvalidatemerchant=s=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:s.validationURL,parentOrigin:window.location.origin}}).then(r=>i.completeMerchantValidation(r)).catch(r=>{i.abort(),a.reject(r)}),i.onpaymentauthorized=s=>{var o;const r={receipt:JSON.stringify({token:s.payment.token}),receiptBillingData:{email:(o=s.payment.shippingContact)==null?void 0:o.emailAddress}};i.completePayment(ApplePaySession.STATUS_SUCCESS),a.resolve(r)},i.oncancel=t,i.begin(),a.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(i){return y(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){h(!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(de(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:s}=a;return s?this.generateGooglePayReceipt({nativePayData:s,onCancel:n}).then(r=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:r})):a})}renderForm(e){return h(!e.selector,"selector is required for renderForm"),h(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){qe(!!e&&!R.has(e),`Invalid locale. Supported languages (${[...R].join(" | ")})`);const t=R.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return h(!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=>{h(!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={},s=new Map;let r=!1;return A(this,Y,Me).call(this,i),{create:o=>{var L,O;if("value"in o)return h(o.elementType!=="cardHolderName",`Value is not allowed! for ${o.elementType}`),this.defaultCardHolderName=o.value,{mount:()=>{},on:()=>{},off:()=>!0,focus:()=>{},blur:()=>{},clear:()=>{this.defaultCardHolderName=""}};const{elementType:l,elementOptions:g}=o,m=new Map;let u=null;const b=S(S({},t),g.classes),k=((L=b==null?void 0:b.focus)==null?void 0:L.split(" "))||["MoneyHashElement--focus"],E=((O=b==null?void 0:b.error)==null?void 0:O.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const f=document.querySelector(g.selector);h(!f,`Couldn't find an element with selector ${g.selector}!`),f.classList.add("MoneyHashElement"),i.push(te=>{var pe,me,ue,he,ge,ye,fe,we,be;const{type:U,data:_}=te.data;if(U===`${l}@mount`&&(a[l]=_.isValid,(pe=m.get(`${l}@mount`))==null||pe()),U===`${l}@focus`){f.classList.add(...k),(me=m.get(`${l}@focus`))==null||me();return}if(U===`${l}@blur`){f.classList.remove(...k),(ue=m.get(`${l}@blur`))==null||ue();return}if(U===`${l}@error`){_.isValid?f.classList.remove(...E):f.classList.add(...E),(he=m.get(`${l}@error`))==null||he(_);return}if(U===`${l}@changeInput`){if((ge=m.get(`${l}@changeInput`))==null||ge({isValid:_.isValid,length:_.length}),a[l]=_.isValid,s.get("validityChange")){const ie=Object.values(a).every(Boolean);ie!==r&&((ye=s.get("validityChange"))==null||ye(ie),r=ie)}return}if(U===`${l}@cardNumberChange`){(fe=m.get(`${l}@cardNumberChange`))==null||fe(_);return}if(U===`${l}@key:Backspace`){(we=m.get(`${l}@key:Backspace`))==null||we();return}U===`${l}@key:Enter`&&((be=m.get(`${l}@key:Enter`))==null||be())}),u=A(this,z,Le).call(this,{container:f,elementType:l,elementOptions:g,styles:S(S({},e),g.styles),fontSourceCss:n}),this.mountedCardElements.push(l)},on:(f,te)=>{m.set(`${l}@${f}`,te)},off:f=>m.delete(`${l}@${f}`),focus:()=>{var f;(f=u==null?void 0:u.contentWindow)==null||f.postMessage({type:"focus"},q())},blur:()=>{var f;(f=u==null?void 0:u.contentWindow)==null||f.postMessage({type:"blur"},q())},clear:()=>{var f;(f=u==null?void 0:u.contentWindow)==null||f.postMessage({type:"clear"},q())}}},on:(o,l)=>{s.set(o,l)},off(o){s.delete(o)}}}submitForm(o){return y(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:i,saveCard:a,paymentMethod:s="CARD",installmentPlanData:r}){let l;if(t){const m=le(this.mountedCardElements);h(!!m,`You must mount ${m} element!`),l=yield A(this,N,re).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:s,lang:this.sdkEmbed.lang,billingData:n,shippingData:i,cardEmbed:l,saveCard:a,installmentPlanData:r}})})}selectInstallmentPlan(i){return y(this,arguments,function*({intentId:e,planId:t,issuerCode:n}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:n,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(i){return y(this,arguments,function*({first6Digits:e,amount:t,currency:n}){return h(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:n,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(i){return y(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:n}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:n,lang:this.sdkEmbed.lang}})})}renderUrl(a){return y(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:i}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return A(this,j,Se).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,G,Ce).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return A(this,K,Re).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),i=setInterval(()=>y(this,null,function*(){const a=new Date;n<a&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}H=new WeakSet,ne=function(e){var n,i;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[S({type:"CARD",parameters:{allowedAuthMethods:((n=this.options.googlePay)==null?void 0:n.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((i=this.options.googlePay)==null?void 0:i.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},W=new WeakSet,Ee=function(){var e;return((e=this.options.googlePay)==null?void 0:e.collectibleBillingData)||["email"]},$=new WeakSet,se=function(){var e;return((e=this.options.applePay)==null?void 0:e.collectibleBillingData)||["email"]},N=new WeakSet,re=function(t){return y(this,arguments,function*({accessToken:e}){const n=new B;this.vaultSubmitListener.current=s=>{const{type:r,data:o}=s.data;r==="vaultSubmit:success"&&n.resolve(o),r==="vaultSubmit:error"&&n.reject(o)};const i=A(this,J,Ue).call(this,{accessToken:e,defaultCardHolderName:this.defaultCardHolderName}),a=yield n.promise;return i.remove(),a})},j=new WeakSet,Se=function(n){return y(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");h(!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,D,oe).call(this,{intentId:e}),a.remove()})},G=new WeakSet,Ce=function(i){return y(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:a=600,height:s=400,left:r=200,top:o=200}=n.window||{},l=window.open(t,"",`width=${a},height=${s},left=${r},top=${o}`);h(!l,"Popup blocked by browser!"),yield A(this,D,oe).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},K=new WeakSet,Re=function(n){return y(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},D=new WeakSet,oe=function(n){return y(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new B,a=s=>y(this,null,function*(){var o,l,g,m;if(s.origin!==p())return;const{type:r}=s.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),Te(2)]),b=u.transaction.status.split(".")[1];b==="successful"||b.startsWith("pending")?(l=(o=this.options).onComplete)==null||l.call(o,S({type:this.options.type},u)):(m=(g=this.options).onFail)==null||m.call(g,S({type:this.options.type},u)),i.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),i.promise})},Y=new WeakSet,Me=function(e){const t=n=>{n.origin===q()&&e.forEach(i=>{i(n)})};window.addEventListener("message",t)},x=new WeakSet,Ie=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},z=new WeakSet,Le=function({container:e,elementType:t,elementOptions:n,styles:i,fontSourceCss:a}){var l,g,m,u,b;const s=q(),r=new URL(`${s}/vaultField/vaultField.html`);a&&r.searchParams.set("fontSourceCss",a),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((l=n.validation)==null?void 0:l.required)!==void 0&&r.searchParams.set("required",`${(g=n.validation)==null?void 0:g.required}`),r.searchParams.set("placeholder",(m=n.placeholder)!=null?m:""),r.searchParams.set("inputMode",(u=n.inputMode)!=null?u:""),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 o=document.createElement("iframe");return o.src=r.toString(),o.style.height=(b=i==null?void 0:i.height)!=null?b:"40px",o.style.setProperty("overflow","hidden","important"),o.style.setProperty("display","block","important"),o.style.setProperty("width","100%","important"),o.style.setProperty("maxWidth","100%","important"),o.style.setProperty("border","0","important"),o.style.setProperty("margin","0","important"),o.style.setProperty("padding","0","important"),o.style.setProperty("userSelect","none","important"),o.style.setProperty("colorScheme","light only","important"),e.replaceChildren(o),o},J=new WeakSet,Ue=function({accessToken:e,defaultCardHolderName:t}){const n=q(),i=_e(),a=new URL(`${n}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang),t&&a.searchParams.set("default_card_holder_name",t);const s=document.createElement("iframe");return s.id="moneyhash-submit-iframe",s.src=a.toString(),s.hidden=!0,document.body.appendChild(s),s},d.IFrameSandboxOptions=V,d.default=Fe,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 H,ne,W,Ee,$,se,N,re,j,Se,G,Ce,K,Re,D,oe,Y,Me,x,Ie,z,Le,J,Ue;"use strict";var He=Object.defineProperty,$e=Object.defineProperties;var Ne=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var Pe=Object.prototype.hasOwnProperty,ke=Object.prototype.propertyIsEnumerable;var ae=(d,c,p)=>c in d?He(d,c,{enumerable:!0,configurable:!0,writable:!0,value:p}):d[c]=p,S=(d,c)=>{for(var p in c||(c={}))Pe.call(c,p)&&ae(d,p,c[p]);if(X)for(var p of X(c))ke.call(c,p)&&ae(d,p,c[p]);return d},Q=(d,c)=>$e(d,Ne(c));var Ae=(d,c)=>{var p={};for(var v in d)Pe.call(d,v)&&c.indexOf(v)<0&&(p[v]=d[v]);if(d!=null&&X)for(var v of X(d))c.indexOf(v)<0&&ke.call(d,v)&&(p[v]=d[v]);return p};var w=(d,c,p)=>(ae(d,typeof c!="symbol"?c+"":c,p),p),ve=(d,c,p)=>{if(!c.has(d))throw TypeError("Cannot "+p)};var Z=(d,c,p)=>(ve(d,c,"read from private field"),p?p.call(d):c.get(d)),C=(d,c,p)=>{if(c.has(d))throw TypeError("Cannot add the same private member more than once");c instanceof WeakSet?c.add(d):c.set(d,p)};var A=(d,c,p)=>(ve(d,c,"access private method"),p);var y=(d,c,p)=>new Promise((v,I)=>{var V=R=>{try{T(p.next(R))}catch(F){I(F)}},h=R=>{try{T(p.throw(R))}catch(F){I(F)}},T=R=>R.done?v(R.value):Promise.resolve(R.value).then(V,h);T((p=p.apply(d,c)).next())});class c{constructor(e){w(this,"target");w(this,"targetOrigin");w(this,"listeners");w(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function p(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function v(){return typeof window!="undefined"}const M=class{constructor(){v()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=p(),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.13.1");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),M.messagingService=new c({target:n.contentWindow,targetOrigin:e}),M.isCommunicationReady=new Promise(i=>{var s;const a=r=>{var o;r.data.type==="headlessSDK:init"&&(i(),(o=M.messagingService)==null||o.removeListener(a))};(s=M.messagingService)==null||s.onReceive(a)})}request(n){return y(this,arguments,function*({api:e,payload:t}){return yield M.isCommunicationReady,new Promise((i,a)=>{var r,o;(r=M.messagingService)==null||r.send({type:e,data:t});const s=l=>{var u;const{type:g,data:m}=l.data;g===e&&(m.status==="resolved"?i(m.payload):a(m.payload),(u=M.messagingService)==null||u.removeListener(s))};(o=M.messagingService)==null||o.onReceive(s)})})}postMessage(e){var t;(t=M.messagingService)==null||t.send({type:e})}};let I=M;w(I,"messagingService",null),w(I,"isCommunicationReady");const V=["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 h(P,e){if(P)throw new Error(e)}const T=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class F{constructor(e){w(this,"options");w(this,"messagingService",null);w(this,"iframe",null);w(this,"isCommunicationReady",null);h(!T.has(e.type),`MoneyHash constructor must be called with valid type (${[...T].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 l,g;(l=this.messagingService)==null||l.abortService();const a=p(),s=new URL(`${a}/embed/${this.options.type}/${t}`);s.searchParams.set("sdk","true"),s.searchParams.set("parent",window.location.origin),s.searchParams.set("version","js@1.13.1"),i&&s.searchParams.set("onDimensionsChange","true");const r=(g=this.options.locale)==null?void 0:g.split("-")[0];r&&s.searchParams.set("lang",r),this.iframe=document.createElement("iframe"),this.iframe.src=s.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",n&&n.forEach(m=>{var u;V.includes(m)&&((u=this.iframe)==null||u.sandbox.add(m))});const o=document.querySelector(e);return h(!o,`Couldn't find an element with selector ${e}!`),o.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:a}),this.isCommunicationReady=new Promise(m=>{var b;const u=k=>{var E;k.data.type==="sdk:init"&&(m(),(E=this.messagingService)==null||E.removeListener(u))};(b=this.messagingService)==null||b.onReceive(u)}),this.messagingService.onReceive((m,u)=>{var E,L,O,f;const{type:b,data:k}=m.data;switch(b){case"sdk:init":{u({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(L=(E=this.options).onComplete)==null||L.call(E,S({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(f=(O=this.options).onFail)==null||f.call(O,S({type:this.options.type},k)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{i==null||i(k.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return y(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 y(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class B{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function _e(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function q(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function le(P){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!P.includes(t))return t;return null}function de(P){return(Array.isArray(P)?P.length:Object.keys(P).length)===0}function ee(P,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=P,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(a)})}function Te(P){return new Promise(e=>{setTimeout(()=>{e("done")},P*1e3)})}function qe(P,e){P&&console.warn(e)}const ce=new Set(["method","customerBalance","savedCard"]);class Fe{constructor(e){C(this,H);C(this,W);C(this,$);C(this,N);C(this,j);C(this,G);C(this,K);C(this,D);C(this,Y);C(this,x);C(this,z);C(this,J);w(this,"options");w(this,"sdkApiHandler",new I);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);w(this,"googlePaymentsClient",null);w(this,"cardForm",{collect:()=>y(this,null,function*(){h(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=le(this.mountedCardElements);h(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,N,re).call(this,{accessToken:t})}),pay:r=>y(this,[r],function*({intentId:e,cardData:t,saveCard:n,billingData:i,shippingData:a,installmentPlanData:s}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:i,shippingData:a,cardEmbed:t,saveCard:n,installmentPlanData:s}})}),createCardToken:n=>y(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}})}),binLookup:n=>y(this,[n],function*({cardData:e,flowId:t}){return this.sdkApiHandler.request({api:"sdk:binLookup",payload:{cardData:e,flowId:t,publicApiKey:this.options.publicApiKey}})})});w(this,"defaultCardHolderName","");this.options=e,this.sdkEmbed=new F(Q(S({},e),{headless:!0})),A(this,x,Ie).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(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),h(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:{intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey,operation:e.operation,currency:e.currency,amount:e.amount,customer:e.customer,flowId:e.flowId,custom_fields:e.customFields}}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:i,metaData:a,installmentPlanData:s}){return h(!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:n,lang:this.sdkEmbed.lang,useWalletBalance:i,metaData:a,installmentPlanData:s}})}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(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 y(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:i,onCancel:a=()=>{},onError:s,onComplete:r,billingData:o={}}){if(yield ee("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const g=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${n}`},requiredShippingContactFields:Z(this,$,se)}),{state:m,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="FORM_FIELDS"){if(de(o))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:o}})}}catch(k){throw yield this.resetSelectedMethod(e),k}const b=new B;return g.onvalidatemerchant=k=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{secret:u.secret,validationUrl:k.validationURL,parentOrigin:window.location.origin}}).then(E=>g.completeMerchantValidation(E)).catch(s),g.onpaymentauthorized=k=>{var E;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:JSON.stringify({token:k.payment.token}),receiptBillingData:{email:(E=k.payment.shippingContact)==null?void 0:E.emailAddress}}}).then(L=>{g.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(L),b.resolve(L)}).catch(()=>{g.completePayment(ApplePaySession.STATUS_FAILURE),s==null||s(),b.reject(void 0)})},g.oncancel=a,g.begin(),b.promise})}renderGooglePayButton(n){return y(this,null,function*(){var i=n,{onClick:e}=i,t=Ae(i,["onClick"]);var r;const a=document.getElementById("moneyHash-google-pay-button");h(!a,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ee("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const s=A(this,H,ne).call(this);this.googlePaymentsClient.isReadyToPay(s).then(o=>{if(o.result){const l=this.googlePaymentsClient.createButton(Q(S({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:s.allowedPaymentMethods,onClick:e}));a==null||a.replaceChildren(l)}else throw new Error("Google Pay is not ready to pay!")}).catch(o=>{console.dir(o)})})}generateGooglePayReceipt({nativePayData:e,onCancel:t}){return h(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "generateGooglePayReceipt"'),h(!e,"nativePayData is required to generate Google Pay receipt!"),h(!e.amount,"nativePayData.amount is required to generate Google Pay receipt!"),this.googlePaymentsClient.loadPaymentData(Q(S({},A(this,H,ne).call(this,e)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${e.amount}`,currencyCode:e.currency_code,countryCode:e.country_code},merchantInfo:{merchantName:e.merchant_name,merchantId:e.merchant_id},emailRequired:Z(this,W,Ee).includes("email")})).then(n=>({receipt:n.paymentMethodData.tokenizationData.token,receiptBillingData:{email:n.email}})).catch(n=>(n.statusCode==="CANCELED"?t==null||t():console.dir(n),Promise.reject(n)))}generateApplePayReceipt(n){return y(this,arguments,function*({nativePayData:e,onCancel:t=()=>{}}){if(yield ee("https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),h(!e,"nativePayData is required to generate Apple Pay receipt!"),!e)return{receipt:"",receiptBillingData:{}};if(h(!e.amount,"nativePayData.amount is required to generate Apple Pay receipt!"),!ApplePaySession)throw new Error("Apple Pay is not supported!");const i=new ApplePaySession(3,{countryCode:e.country_code,currencyCode:e.currency_code,supportedNetworks:e.supported_networks,merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${e.amount}`},requiredShippingContactFields:Z(this,$,se)}),a=new B;return i.onvalidatemerchant=s=>this.sdkApiHandler.request({api:"sdk:applePaySession",payload:{methodId:e.method_id,validationUrl:s.validationURL,parentOrigin:window.location.origin}}).then(r=>i.completeMerchantValidation(r)).catch(r=>{i.abort(),a.reject(r)}),i.onpaymentauthorized=s=>{var o;const r={receipt:JSON.stringify({token:s.payment.token}),receiptBillingData:{email:(o=s.payment.shippingContact)==null?void 0:o.emailAddress}};i.completePayment(ApplePaySession.STATUS_SUCCESS),a.resolve(r)},i.oncancel=t,i.begin(),a.promise})}submitPaymentReceipt({intentId:e,nativeReceiptData:t}){return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,lang:this.sdkEmbed.lang,receipt:t.receipt,receiptBillingData:t.receiptBillingData}})}payWithGooglePay(i){return y(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){h(!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(de(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:s}=a;return s?this.generateGooglePayReceipt({nativePayData:s,onCancel:n}).then(r=>this.submitPaymentReceipt({intentId:e,nativeReceiptData:r})):a})}renderForm(e){return h(!e.selector,"selector is required for renderForm"),h(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){qe(!!e&&!R.has(e),`Invalid locale. Supported languages (${[...R].join(" | ")})`);const t=R.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return h(!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=>{h(!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={},s=new Map;let r=!1;return A(this,Y,Me).call(this,i),{create:o=>{var L,O;if("value"in o)return h(o.elementType!=="cardHolderName",`Value is not allowed! for ${o.elementType}`),this.defaultCardHolderName=o.value,{mount:()=>{},on:()=>{},off:()=>!0,focus:()=>{},blur:()=>{},clear:()=>{this.defaultCardHolderName=""}};const{elementType:l,elementOptions:g}=o,m=new Map;let u=null;const b=S(S({},t),g.classes),k=((L=b==null?void 0:b.focus)==null?void 0:L.split(" "))||["MoneyHashElement--focus"],E=((O=b==null?void 0:b.error)==null?void 0:O.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const f=document.querySelector(g.selector);h(!f,`Couldn't find an element with selector ${g.selector}!`),f.classList.add("MoneyHashElement"),i.push(te=>{var pe,me,ue,he,ge,ye,fe,we,be;const{type:U,data:_}=te.data;if(U===`${l}@mount`&&(a[l]=_.isValid,(pe=m.get(`${l}@mount`))==null||pe()),U===`${l}@focus`){f.classList.add(...k),(me=m.get(`${l}@focus`))==null||me();return}if(U===`${l}@blur`){f.classList.remove(...k),(ue=m.get(`${l}@blur`))==null||ue();return}if(U===`${l}@error`){_.isValid?f.classList.remove(...E):f.classList.add(...E),(he=m.get(`${l}@error`))==null||he(_);return}if(U===`${l}@changeInput`){if((ge=m.get(`${l}@changeInput`))==null||ge({isValid:_.isValid,length:_.length}),a[l]=_.isValid,s.get("validityChange")){const ie=Object.values(a).every(Boolean);ie!==r&&((ye=s.get("validityChange"))==null||ye(ie),r=ie)}return}if(U===`${l}@cardNumberChange`){(fe=m.get(`${l}@cardNumberChange`))==null||fe(_);return}if(U===`${l}@key:Backspace`){(we=m.get(`${l}@key:Backspace`))==null||we();return}U===`${l}@key:Enter`&&((be=m.get(`${l}@key:Enter`))==null||be())}),u=A(this,z,Le).call(this,{container:f,elementType:l,elementOptions:g,styles:S(S({},e),g.styles),fontSourceCss:n}),this.mountedCardElements.push(l)},on:(f,te)=>{m.set(`${l}@${f}`,te)},off:f=>m.delete(`${l}@${f}`),focus:()=>{var f;(f=u==null?void 0:u.contentWindow)==null||f.postMessage({type:"focus"},q())},blur:()=>{var f;(f=u==null?void 0:u.contentWindow)==null||f.postMessage({type:"blur"},q())},clear:()=>{var f;(f=u==null?void 0:u.contentWindow)==null||f.postMessage({type:"clear"},q())}}},on:(o,l)=>{s.set(o,l)},off(o){s.delete(o)}}}submitForm(o){return y(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:i,saveCard:a,paymentMethod:s="CARD",installmentPlanData:r}){let l;if(t){const m=le(this.mountedCardElements);h(!!m,`You must mount ${m} element!`),l=yield A(this,N,re).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:s,lang:this.sdkEmbed.lang,billingData:n,shippingData:i,cardEmbed:l,saveCard:a,installmentPlanData:r}})})}selectInstallmentPlan(i){return y(this,arguments,function*({intentId:e,planId:t,issuerCode:n}){return this.sdkApiHandler.request({api:"sdk:selectInstallmentPlan",payload:{planId:t,intentId:e,issuerCode:n,lang:this.sdkEmbed.lang}})})}getInstallmentPlans(i){return y(this,arguments,function*({first6Digits:e,amount:t,currency:n}){return h(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get installment plans!"),this.sdkApiHandler.request({api:"sdk:getInstallmentPlans",payload:{first6Digits:e,amount:t,currency:n,publicApiKey:this.options.publicApiKey,lang:this.sdkEmbed.lang}})})}submitCvv(i){return y(this,arguments,function*({intentId:e,cvv:t,installmentPlanData:n}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,installmentPlanData:n,lang:this.sdkEmbed.lang}})})}renderUrl(a){return y(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:i}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return A(this,j,Se).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,G,Ce).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return A(this,K,Re).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),i=setInterval(()=>y(this,null,function*(){const a=new Date;n<a&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}H=new WeakSet,ne=function(e){var n,i;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[S({type:"CARD",parameters:{allowedAuthMethods:((n=this.options.googlePay)==null?void 0:n.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((i=this.options.googlePay)==null?void 0:i.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},W=new WeakSet,Ee=function(){var e;return((e=this.options.googlePay)==null?void 0:e.collectibleBillingData)||["email"]},$=new WeakSet,se=function(){var e;return((e=this.options.applePay)==null?void 0:e.collectibleBillingData)||["email"]},N=new WeakSet,re=function(t){return y(this,arguments,function*({accessToken:e}){const n=new B;this.vaultSubmitListener.current=s=>{const{type:r,data:o}=s.data;r==="vaultSubmit:success"&&n.resolve(o),r==="vaultSubmit:error"&&n.reject(o)};const i=A(this,J,Ue).call(this,{accessToken:e,defaultCardHolderName:this.defaultCardHolderName}),a=yield n.promise;return i.remove(),a})},j=new WeakSet,Se=function(n){return y(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");h(!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,D,oe).call(this,{intentId:e}),a.remove()})},G=new WeakSet,Ce=function(i){return y(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:a=600,height:s=400,left:r=200,top:o=200}=n.window||{},l=window.open(t,"",`width=${a},height=${s},left=${r},top=${o}`);h(!l,"Popup blocked by browser!"),yield A(this,D,oe).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},K=new WeakSet,Re=function(n){return y(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},D=new WeakSet,oe=function(n){return y(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new B,a=s=>y(this,null,function*(){var o,l,g,m;if(s.origin!==p())return;const{type:r}=s.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),Te(2)]),b=u.transaction.status.split(".")[1];b==="successful"||b.startsWith("pending")?(l=(o=this.options).onComplete)==null||l.call(o,S({type:this.options.type},u)):(m=(g=this.options).onFail)==null||m.call(g,S({type:this.options.type},u)),i.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),i.promise})},Y=new WeakSet,Me=function(e){const t=n=>{n.origin===q()&&e.forEach(i=>{i(n)})};window.addEventListener("message",t)},x=new WeakSet,Ie=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},z=new WeakSet,Le=function({container:e,elementType:t,elementOptions:n,styles:i,fontSourceCss:a}){var l,g,m,u,b;const s=q(),r=new URL(`${s}/vaultField/vaultField.html`);a&&r.searchParams.set("fontSourceCss",a),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((l=n.validation)==null?void 0:l.required)!==void 0&&r.searchParams.set("required",`${(g=n.validation)==null?void 0:g.required}`),r.searchParams.set("placeholder",(m=n.placeholder)!=null?m:""),r.searchParams.set("inputMode",(u=n.inputMode)!=null?u:""),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 o=document.createElement("iframe");return o.src=r.toString(),o.style.height=(b=i==null?void 0:i.height)!=null?b:"40px",o.style.setProperty("overflow","hidden","important"),o.style.setProperty("display","block","important"),o.style.setProperty("width","100%","important"),o.style.setProperty("maxWidth","100%","important"),o.style.setProperty("border","0","important"),o.style.setProperty("margin","0","important"),o.style.setProperty("padding","0","important"),o.style.setProperty("userSelect","none","important"),o.style.setProperty("colorScheme","light only","important"),e.replaceChildren(o),o},J=new WeakSet,Ue=function({accessToken:e,defaultCardHolderName:t}){const n=q(),i=_e(),a=new URL(`${n}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang),t&&a.searchParams.set("default_card_holder_name",t);const s=document.createElement("iframe");return s.id="moneyhash-submit-iframe",s.src=a.toString(),s.hidden=!0,document.body.appendChild(s),s},d.IFrameSandboxOptions=V,d.default=Fe,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var d=Object.defineProperty;var a=(t,e,s)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var n=(t,e,s)=>(a(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-b7250ca2.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-b0d52042.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-833ad597.js"; | ||
import { S as o, t as d, w as u, s as a } from "./warnIf-f9d184c7.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.13.0"),w&&d.searchParams.set("onDimensionsChange","true");const L=(O=this.options.locale)==null?void 0:O.split("-")[0];L&&d.searchParams.set("lang",L),this.iframe=document.createElement("iframe"),this.iframe.src=d.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",R&&R.forEach(h=>{var c;i.includes(h)&&((c=this.iframe)==null||c.sandbox.add(h))});const k=document.querySelector(e);return l(!k,`Couldn't find an element with selector ${e}!`),k.replaceChildren(this.iframe),this.messagingService=new s({target:this.iframe.contentWindow,targetOrigin:I}),this.isCommunicationReady=new Promise(h=>{var y;const c=p=>{var f;p.data.type==="sdk:init"&&(h(),(f=this.messagingService)==null||f.removeListener(c))};(y=this.messagingService)==null||y.onReceive(c)}),this.messagingService.onReceive((h,c)=>{var f,F,C,P;const{type:y,data:p}=h.data;switch(y){case"sdk:init":{c({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(F=(f=this.options).onComplete)==null||F.call(f,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(P=(C=this.options).onFail)==null||P.call(C,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{w==null||w(p.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return E(this,null,function*(){var n;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(n=this.messagingService)==null||n.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return E(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function u(a,e){a&&console.warn(e)}class r{constructor(e){o(this,"options");o(this,"sdkEmbed");this.options=e,this.sdkEmbed=new v(e)}start(e){return l(!e.selector,"selector is required for start"),l(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){u(!!e&&!g.has(e),`Invalid locale. Supported languages (${[...g].join(" | ")})`);const n=g.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return r}); | ||
(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.13.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.13.0", | ||
"version": "1.13.1", | ||
"description": "MoneyHash JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "type": "module", |
429056
3551