@moneyhash/js-sdk
Advanced tools
Comparing version 1.7.3 to 1.8.0
@@ -1,1 +0,1 @@ | ||
"use strict";var we=Object.defineProperty,Pe=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var T=(o,e,t)=>e in o?we(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,w=(o,e)=>{for(var t in e||(e={}))ne.call(e,t)&&T(o,t,e[t]);if(U)for(var t of U(e))re.call(e,t)&&T(o,t,e[t]);return o},_=(o,e)=>Pe(o,be(e));var se=(o,e)=>{var t={};for(var r in o)ne.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&U)for(var r of U(o))e.indexOf(r)<0&&re.call(o,r)&&(t[r]=o[r]);return t};var f=(o,e,t)=>(T(o,typeof e!="symbol"?e+"":e,t),t),ke=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var P=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)};var y=(o,e,t)=>(ke(o,e,"access private method"),t);var g=(o,e,t)=>new Promise((r,a)=>{var s=n=>{try{i(t.next(n))}catch(c){a(c)}},d=n=>{try{i(t.throw(n))}catch(c){a(c)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,d);i((t=t.apply(o,e)).next())});const p=require("./warnIf-41ece814.cjs");function Ee(){return typeof window!="undefined"}const b=class{constructor(){Ee()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=p.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.7.3");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),b.messagingService=new p.MessagingService({target:r.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(a=>{var d;const s=i=>{var n;i.data.type==="headlessSDK:init"&&(a(),(n=b.messagingService)==null||n.removeListener(s))};(d=b.messagingService)==null||d.onReceive(s)})}request(r){return g(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((a,s)=>{var i,n;(i=b.messagingService)==null||i.send({type:e,data:t});const d=c=>{var m;const{type:l,data:h}=c.data;l===e&&(h.status==="resolved"?a(h.payload):s(h.payload),(m=b.messagingService)==null||m.removeListener(d))};(n=b.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=b.messagingService)==null||t.send({type:e})}};let S=b;f(S,"messagingService",null),f(S,"isCommunicationReady");class G{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Ae(){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 ie(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function oe(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function de(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function ce(o,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=o,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function ve(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const le=new Set(["method","customerBalance","savedCard"]);var L,O,M,Y,$,he,F,pe,q,ue,R,B,H,me,N,ge,D,ye,V,fe;class Ie{constructor(e){P(this,L);P(this,M);P(this,$);P(this,F);P(this,q);P(this,R);P(this,H);P(this,N);P(this,D);P(this,V);f(this,"options");f(this,"sdkApiHandler",new S);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>g(this,null,function*(){p.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=oe(this.mountedCardElements);p.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,M,Y).call(this,{accessToken:t})}),pay:i=>g(this,[i],function*({intentId:e,cardData:t,saveCard:r,billingData:a,shippingData:s,useWalletBalance:d}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:s,cardEmbed:t,useWalletBalance:d,saveCard:r}})}),createCardToken:r=>g(this,[r],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new p.SDKEmbed(_(w({},e),{headless:!0})),y(this,N,ge).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(p.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),p.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:w({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:r,useWalletBalance:a,metaData:s}){return p.throwIf(!le.has(t),`type must be a valid one (${[...le].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData: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 p.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return g(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:a,onCancel:s=()=>{},onError:d,onComplete:i,billingData:n={}}){if(yield ce("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:h,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(h==="FORM_FIELDS"){if(de(n))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:n}})}}catch(A){throw yield this.resetSelectedMethod(e),A}const E=new G;l.onvalidatemerchant=A=>{fetch(`${ie()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:A.validationURL})}).then(k=>k.ok?k.json():Promise.reject()).then(k=>l.completeMerchantValidation(k)).catch(d)},l.onpaymentauthorized=A=>{fetch(`${ie()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:A.payment.token},secret:m.secret})}).then(k=>k.ok?k.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),i==null||i(),E.resolve(void 0)}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d(),E.reject(void 0)})},l.oncancel=s,l.begin(),yield E.promise})}renderGooglePayButton(r){return g(this,null,function*(){var a=r,{onClick:e}=a,t=se(a,["onClick"]);var i;const s=document.getElementById("moneyHash-google-pay-button");p.throwIf(!s,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ce("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((i=this.options.googlePay)==null?void 0:i.environment)||"PRODUCTION"});const d=y(this,L,O).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const c=this.googlePaymentsClient.createButton(_(w({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:d.allowedPaymentMethods,onClick:e}));s==null||s.replaceChildren(c)}else throw new Error("Google Pay is not ready to pay!")}).catch(n=>{console.dir(n)})})}payWithGooglePay(a){return g(this,arguments,function*({intentId:e,billingData:t={},onCancel:r}){p.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let s=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(s.state==="FORM_FIELDS"){if(de(t))throw new Error("Billing data is missing while calling payWithGooglePay");s=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(i){throw yield this.resetSelectedMethod(e),i}const{__nativePayData__:d}=s;return d?this.googlePaymentsClient.loadPaymentData(_(w({},y(this,L,O).call(this,d)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${d.amount}`,currencyCode:d.currency_code,countryCode:d.country_code},merchantInfo:{merchantName:d==null?void 0:d.merchant_name,merchantId:d==null?void 0:d.merchant_id}})).then(i=>{const n=i.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:n}})}).catch(i=>(i.statusCode==="CANCELED"?r==null||r():console.dir(i),Promise.reject(i))):s})}renderForm(e){return p.throwIf(!e.selector,"selector is required for renderForm"),p.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){p.warnIf(!!e&&!p.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...p.supportedLanguages].join(" | ")})`);const t=p.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return p.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(r=>{p.throwIf(!r.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:r}){const a=[],s={},d=new Map;let i=!1;return y(this,H,me).call(this,a),{create:({elementType:n,elementOptions:c})=>{var k,x;const l=new Map;let h=null;const m=w(w({},t),c.classes),E=((k=m==null?void 0:m.focus)==null?void 0:k.split(" "))||["MoneyHashElement--focus"],A=((x=m==null?void 0:m.error)==null?void 0:x.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const u=document.querySelector(c.selector);p.throwIf(!u,`Couldn't find an element with selector ${c.selector}!`),u.classList.add("MoneyHashElement"),a.push(W=>{var K,z,J,X,Q,Z,ee,te,ae;const{type:v,data:I}=W.data;if(v===`${n}@mount`&&(s[n]=I.isValid,(K=l.get(`${n}@mount`))==null||K()),v===`${n}@focus`){u.classList.add(...E),(z=l.get(`${n}@focus`))==null||z();return}if(v===`${n}@blur`){u.classList.remove(...E),(J=l.get(`${n}@blur`))==null||J();return}if(v===`${n}@error`){I.isValid?u.classList.remove(...A):u.classList.add(...A),(X=l.get(`${n}@error`))==null||X(I);return}if(v===`${n}@changeInput`){if((Q=l.get(`${n}@changeInput`))==null||Q({isValid:I.isValid,length:I.length}),s[n]=I.isValid,d.get("validityChange")){const j=Object.values(s).every(Boolean);j!==i&&((Z=d.get("validityChange"))==null||Z(j),i=j)}return}if(v===`${n}@cardNumberChange`){(ee=l.get(`${n}@cardNumberChange`))==null||ee(I);return}if(v===`${n}@key:Backspace`){(te=l.get(`${n}@key:Backspace`))==null||te();return}v===`${n}@key:Enter`&&((ae=l.get(`${n}@key:Enter`))==null||ae())}),h=y(this,D,ye).call(this,{container:u,elementType:n,elementOptions:c,styles:w(w({},e),c.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(u,W)=>{l.set(`${n}@${u}`,W)},off:u=>l.delete(`${n}@${u}`),focus:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"focus"},C())},blur:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"blur"},C())},clear:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"clear"},C())}}},on:(n,c)=>{d.set(n,c)}}}submitForm(n){return g(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:a,saveCard:s,paymentMethod:d="CARD",useWalletBalance:i}){let c;if(t){const h=oe(this.mountedCardElements);p.throwIf(!!h,`You must mount ${h} element!`),c=yield y(this,M,Y).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:d,lang:this.sdkEmbed.lang,billingData:r,shippingData:a,cardEmbed:c,useWalletBalance:i,saveCard:s}})})}submitCvv(r){return g(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(s){return g(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),r){case"IFRAME":return y(this,$,he).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,F,pe).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,q,ue).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const r=new Date(e),a=setInterval(()=>g(this,null,function*(){const s=new Date;r<s&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}L=new WeakSet,O=function(e){var r,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[w({type:"CARD",parameters:{allowedAuthMethods:((r=this.options.googlePay)==null?void 0:r.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((a=this.options.googlePay)==null?void 0:a.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},M=new WeakSet,Y=function(t){return g(this,arguments,function*({accessToken:e}){const r=new G;this.vaultSubmitListener.current=d=>{const{type:i,data:n}=d.data;i==="vaultSubmit:success"&&r.resolve(n),i==="vaultSubmit:error"&&r.reject(n)};const a=y(this,V,fe).call(this,{accessToken:e}),s=yield r.promise;return a.remove(),s})},$=new WeakSet,he=function(r){return g(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");p.throwIf(!a,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=t,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),a==null||a.replaceChildren(s),yield y(this,R,B).call(this,{intentId:e}),s.remove()})},F=new WeakSet,pe=function(a){return g(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:d=400,left:i=200,top:n=200}=r.window||{},c=window.open(t,"",`width=${s},height=${d},left=${i},top=${n}`);p.throwIf(!c,"Popup blocked by browser!"),yield y(this,R,B).call(this,{intentId:e,isUsingPopUp:!0}),c==null||c.close()})},q=new WeakSet,ue=function(r){return g(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},R=new WeakSet,B=function(r){return g(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new G,s=d=>g(this,null,function*(){var n,c,l,h;if(d.origin!==p.getIframeUrl())return;const{type:i}=d.data;if(i==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),ve(2)]),E=m.transaction.status.split(".")[1];E==="successful"||E.startsWith("pending")?(c=(n=this.options).onComplete)==null||c.call(n,w({type:this.options.type},m)):(h=(l=this.options).onFail)==null||h.call(l,w({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),a.promise})},H=new WeakSet,me=function(e){const t=r=>{r.origin===C()&&e.forEach(a=>{a(r)})};window.addEventListener("message",t)},N=new WeakSet,ge=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},D=new WeakSet,ye=function({container:e,elementType:t,elementOptions:r,styles:a,fontSourceCss:s}){var c,l,h,m;const d=C(),i=new URL(`${d}/vaultField/vaultField.html`);s&&i.searchParams.set("fontSourceCss",s),i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((c=r.validation)==null?void 0:c.required)!==void 0&&i.searchParams.set("required",`${(l=r.validation)==null?void 0:l.required}`),i.searchParams.set("placeholder",(h=r.placeholder)!=null?h:""),i.searchParams.set("lang",this.sdkEmbed.lang),i.searchParams.set("direction",(a==null?void 0:a.direction)||""),i.searchParams.set("color",JSON.stringify(a!=null&&a.color?a.color:"#000")),i.searchParams.set("placeholderColor",(a==null?void 0:a.placeholderColor)||"#ccc"),i.searchParams.set("backgroundColor",(a==null?void 0:a.backgroundColor)||"transparent"),i.searchParams.set("fontSize",(a==null?void 0:a.fontSize)||""),i.searchParams.set("fontFamily",(a==null?void 0:a.fontFamily)||""),i.searchParams.set("fontWeight",`${a==null?void 0:a.fontWeight}`),i.searchParams.set("fontStyle",(a==null?void 0:a.fontStyle)||""),i.searchParams.set("padding",(a==null?void 0:a.padding)||"");const n=document.createElement("iframe");return n.src=i.toString(),n.style.height=(m=a==null?void 0:a.height)!=null?m:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n),n},V=new WeakSet,fe=function({accessToken:e}){const t=C(),r=Ae(),a=new URL(`${t}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang);const s=document.createElement("iframe");return s.id="moneyhash-submit-iframe",s.src=a.toString(),s.hidden=!0,document.body.appendChild(s),s};module.exports=Ie; | ||
"use strict";var we=Object.defineProperty,Pe=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var T=(o,e,t)=>e in o?we(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,w=(o,e)=>{for(var t in e||(e={}))ne.call(e,t)&&T(o,t,e[t]);if(_)for(var t of _(e))re.call(e,t)&&T(o,t,e[t]);return o},U=(o,e)=>Pe(o,be(e));var se=(o,e)=>{var t={};for(var r in o)ne.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&_)for(var r of _(o))e.indexOf(r)<0&&re.call(o,r)&&(t[r]=o[r]);return t};var f=(o,e,t)=>(T(o,typeof e!="symbol"?e+"":e,t),t),ke=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var P=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)};var y=(o,e,t)=>(ke(o,e,"access private method"),t);var g=(o,e,t)=>new Promise((r,a)=>{var s=n=>{try{i(t.next(n))}catch(l){a(l)}},d=n=>{try{i(t.throw(n))}catch(l){a(l)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,d);i((t=t.apply(o,e)).next())});Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("./warnIf-64307072.cjs");function Ee(){return typeof window!="undefined"}const b=class{constructor(){Ee()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=h.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.8.0");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),b.messagingService=new h.MessagingService({target:r.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(a=>{var d;const s=i=>{var n;i.data.type==="headlessSDK:init"&&(a(),(n=b.messagingService)==null||n.removeListener(s))};(d=b.messagingService)==null||d.onReceive(s)})}request(r){return g(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((a,s)=>{var i,n;(i=b.messagingService)==null||i.send({type:e,data:t});const d=l=>{var m;const{type:c,data:p}=l.data;c===e&&(p.status==="resolved"?a(p.payload):s(p.payload),(m=b.messagingService)==null||m.removeListener(d))};(n=b.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=b.messagingService)==null||t.send({type:e})}};let C=b;f(C,"messagingService",null),f(C,"isCommunicationReady");class O{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function ve(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function S(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function ie(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function oe(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function de(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function ce(o,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=o,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function Ae(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const le=new Set(["method","customerBalance","savedCard"]);var L,G,M,Y,$,he,F,pe,q,ue,R,B,H,me,N,ge,D,ye,V,fe;class Ie{constructor(e){P(this,L);P(this,M);P(this,$);P(this,F);P(this,q);P(this,R);P(this,H);P(this,N);P(this,D);P(this,V);f(this,"options");f(this,"sdkApiHandler",new C);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>g(this,null,function*(){h.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=oe(this.mountedCardElements);h.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,M,Y).call(this,{accessToken:t})}),pay:d=>g(this,[d],function*({intentId:e,cardData:t,saveCard:r,billingData:a,shippingData:s}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:s,cardEmbed:t,saveCard:r}})}),createCardToken:r=>g(this,[r],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new h.SDKEmbed(U(w({},e),{headless:!0})),y(this,N,ge).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(h.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),h.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:w({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:r,useWalletBalance:a,metaData:s}){return h.throwIf(!le.has(t),`type must be a valid one (${[...le].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData: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.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(l){return g(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:a,onCancel:s=()=>{},onError:d,onComplete:i,billingData:n={}}){if(yield ce("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const c=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:p,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(de(n))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:n}})}}catch(v){throw yield this.resetSelectedMethod(e),v}const E=new O;c.onvalidatemerchant=v=>{fetch(`${ie()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:v.validationURL})}).then(k=>k.ok?k.json():Promise.reject()).then(k=>c.completeMerchantValidation(k)).catch(d)},c.onpaymentauthorized=v=>{fetch(`${ie()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:v.payment.token},secret:m.secret})}).then(k=>k.ok?k.json():Promise.reject()).then(()=>{c.completePayment(ApplePaySession.STATUS_SUCCESS),i==null||i(),E.resolve(void 0)}).catch(()=>{c.completePayment(ApplePaySession.STATUS_FAILURE),d(),E.reject(void 0)})},c.oncancel=s,c.begin(),yield E.promise})}renderGooglePayButton(r){return g(this,null,function*(){var a=r,{onClick:e}=a,t=se(a,["onClick"]);var i;const s=document.getElementById("moneyHash-google-pay-button");h.throwIf(!s,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ce("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((i=this.options.googlePay)==null?void 0:i.environment)||"PRODUCTION"});const d=y(this,L,G).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const l=this.googlePaymentsClient.createButton(U(w({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:d.allowedPaymentMethods,onClick:e}));s==null||s.replaceChildren(l)}else throw new Error("Google Pay is not ready to pay!")}).catch(n=>{console.dir(n)})})}payWithGooglePay(a){return g(this,arguments,function*({intentId:e,billingData:t={},onCancel:r}){h.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let s=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(s.state==="FORM_FIELDS"){if(de(t))throw new Error("Billing data is missing while calling payWithGooglePay");s=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(i){throw yield this.resetSelectedMethod(e),i}const{__nativePayData__:d}=s;return d?this.googlePaymentsClient.loadPaymentData(U(w({},y(this,L,G).call(this,d)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${d.amount}`,currencyCode:d.currency_code,countryCode:d.country_code},merchantInfo:{merchantName:d==null?void 0:d.merchant_name,merchantId:d==null?void 0:d.merchant_id}})).then(i=>{const n=i.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:n}})}).catch(i=>(i.statusCode==="CANCELED"?r==null||r():console.dir(i),Promise.reject(i))):s})}renderForm(e){return h.throwIf(!e.selector,"selector is required for renderForm"),h.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){h.warnIf(!!e&&!h.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...h.supportedLanguages].join(" | ")})`);const t=h.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return h.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(r=>{h.throwIf(!r.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:r}){const a=[],s={},d=new Map;let i=!1;return y(this,H,me).call(this,a),{create:({elementType:n,elementOptions:l})=>{var k,x;const c=new Map;let p=null;const m=w(w({},t),l.classes),E=((k=m==null?void 0:m.focus)==null?void 0:k.split(" "))||["MoneyHashElement--focus"],v=((x=m==null?void 0:m.error)==null?void 0:x.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const u=document.querySelector(l.selector);h.throwIf(!u,`Couldn't find an element with selector ${l.selector}!`),u.classList.add("MoneyHashElement"),a.push(W=>{var K,z,J,X,Q,Z,ee,te,ae;const{type:A,data:I}=W.data;if(A===`${n}@mount`&&(s[n]=I.isValid,(K=c.get(`${n}@mount`))==null||K()),A===`${n}@focus`){u.classList.add(...E),(z=c.get(`${n}@focus`))==null||z();return}if(A===`${n}@blur`){u.classList.remove(...E),(J=c.get(`${n}@blur`))==null||J();return}if(A===`${n}@error`){I.isValid?u.classList.remove(...v):u.classList.add(...v),(X=c.get(`${n}@error`))==null||X(I);return}if(A===`${n}@changeInput`){if((Q=c.get(`${n}@changeInput`))==null||Q({isValid:I.isValid,length:I.length}),s[n]=I.isValid,d.get("validityChange")){const j=Object.values(s).every(Boolean);j!==i&&((Z=d.get("validityChange"))==null||Z(j),i=j)}return}if(A===`${n}@cardNumberChange`){(ee=c.get(`${n}@cardNumberChange`))==null||ee(I);return}if(A===`${n}@key:Backspace`){(te=c.get(`${n}@key:Backspace`))==null||te();return}A===`${n}@key:Enter`&&((ae=c.get(`${n}@key:Enter`))==null||ae())}),p=y(this,D,ye).call(this,{container:u,elementType:n,elementOptions:l,styles:w(w({},e),l.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(u,W)=>{c.set(`${n}@${u}`,W)},off:u=>c.delete(`${n}@${u}`),focus:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"focus"},S())},blur:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"blur"},S())},clear:()=>{var u;(u=p==null?void 0:p.contentWindow)==null||u.postMessage({type:"clear"},S())}}},on:(n,l)=>{d.set(n,l)}}}submitForm(i){return g(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:a,saveCard:s,paymentMethod:d="CARD"}){let n;if(t){const c=oe(this.mountedCardElements);h.throwIf(!!c,`You must mount ${c} element!`),n=yield y(this,M,Y).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:d,lang:this.sdkEmbed.lang,billingData:r,shippingData:a,cardEmbed:n,saveCard:s}})})}submitCvv(r){return g(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(s){return g(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),r){case"IFRAME":return y(this,$,he).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,F,pe).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,q,ue).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const r=new Date(e),a=setInterval(()=>g(this,null,function*(){const s=new Date;r<s&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}L=new WeakSet,G=function(e){var r,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[w({type:"CARD",parameters:{allowedAuthMethods:((r=this.options.googlePay)==null?void 0:r.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((a=this.options.googlePay)==null?void 0:a.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},M=new WeakSet,Y=function(t){return g(this,arguments,function*({accessToken:e}){const r=new O;this.vaultSubmitListener.current=d=>{const{type:i,data:n}=d.data;i==="vaultSubmit:success"&&r.resolve(n),i==="vaultSubmit:error"&&r.reject(n)};const a=y(this,V,fe).call(this,{accessToken:e}),s=yield r.promise;return a.remove(),s})},$=new WeakSet,he=function(r){return g(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");h.throwIf(!a,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=t,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),a==null||a.replaceChildren(s),yield y(this,R,B).call(this,{intentId:e}),s.remove()})},F=new WeakSet,pe=function(a){return g(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:d=400,left:i=200,top:n=200}=r.window||{},l=window.open(t,"",`width=${s},height=${d},left=${i},top=${n}`);h.throwIf(!l,"Popup blocked by browser!"),yield y(this,R,B).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},q=new WeakSet,ue=function(r){return g(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},R=new WeakSet,B=function(r){return g(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new O,s=d=>g(this,null,function*(){var n,l,c,p;if(d.origin!==h.getIframeUrl())return;const{type:i}=d.data;if(i==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),Ae(2)]),E=m.transaction.status.split(".")[1];E==="successful"||E.startsWith("pending")?(l=(n=this.options).onComplete)==null||l.call(n,w({type:this.options.type},m)):(p=(c=this.options).onFail)==null||p.call(c,w({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),a.promise})},H=new WeakSet,me=function(e){const t=r=>{r.origin===S()&&e.forEach(a=>{a(r)})};window.addEventListener("message",t)},N=new WeakSet,ge=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},D=new WeakSet,ye=function({container:e,elementType:t,elementOptions:r,styles:a,fontSourceCss:s}){var l,c,p,m;const d=S(),i=new URL(`${d}/vaultField/vaultField.html`);s&&i.searchParams.set("fontSourceCss",s),i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((l=r.validation)==null?void 0:l.required)!==void 0&&i.searchParams.set("required",`${(c=r.validation)==null?void 0:c.required}`),i.searchParams.set("placeholder",(p=r.placeholder)!=null?p:""),i.searchParams.set("lang",this.sdkEmbed.lang),i.searchParams.set("direction",(a==null?void 0:a.direction)||""),i.searchParams.set("color",JSON.stringify(a!=null&&a.color?a.color:"#000")),i.searchParams.set("placeholderColor",(a==null?void 0:a.placeholderColor)||"#ccc"),i.searchParams.set("backgroundColor",(a==null?void 0:a.backgroundColor)||"transparent"),i.searchParams.set("fontSize",(a==null?void 0:a.fontSize)||""),i.searchParams.set("fontFamily",(a==null?void 0:a.fontFamily)||""),i.searchParams.set("fontWeight",`${a==null?void 0:a.fontWeight}`),i.searchParams.set("fontStyle",(a==null?void 0:a.fontStyle)||""),i.searchParams.set("padding",(a==null?void 0:a.padding)||"");const n=document.createElement("iframe");return n.src=i.toString(),n.style.height=(m=a==null?void 0:a.height)!=null?m:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n),n},V=new WeakSet,fe=function({accessToken:e}){const t=S(),r=ve(),a=new URL(`${t}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang);const s=document.createElement("iframe");return s.id="moneyhash-submit-iframe",s.src=a.toString(),s.hidden=!0,document.body.appendChild(s),s};exports.IFrameSandboxOptions=h.IFrameSandboxOptions;exports.default=Ie; |
@@ -88,2 +88,11 @@ export declare interface AbstractIntent { | ||
export declare interface CheckoutStyle { | ||
hideAmountSidebar?: boolean; | ||
hideHeader?: boolean; | ||
hideLoaderMessage?: boolean; | ||
hideFormHeaderMessage?: boolean; | ||
hideNavigationToPaymentMethods?: boolean; | ||
formOnly?: boolean; | ||
} | ||
declare type CommonElementOptions = { | ||
@@ -279,2 +288,6 @@ selector: string; | ||
export declare const IFrameSandboxOptions: readonly ["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"]; | ||
export declare type IFrameSandboxOptionsType = typeof IFrameSandboxOptions[number]; | ||
declare interface InputAllowedStyle { | ||
@@ -654,2 +667,3 @@ height?: number; | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS Selector MDN} | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox | iframe sandbox MDN} | ||
* @returns Promise<void> | ||
@@ -735,3 +749,3 @@ */ | ||
collect: () => Promise<CardData>; | ||
pay: ({ intentId, cardData, saveCard, billingData, shippingData, useWalletBalance, }: { | ||
pay: ({ intentId, cardData, saveCard, billingData, shippingData, }: { | ||
intentId: string; | ||
@@ -742,3 +756,2 @@ cardData: CardData; | ||
shippingData?: Record<string, unknown> | undefined; | ||
useWalletBalance?: boolean | undefined; | ||
}) => Promise<IntentDetails<TType>>; | ||
@@ -764,3 +777,3 @@ createCardToken: ({ cardIntentId, cardData, }: { | ||
*/ | ||
submitForm({ intentId, accessToken, billingData, shippingData, saveCard, paymentMethod, useWalletBalance, }: { | ||
submitForm({ intentId, accessToken, billingData, shippingData, saveCard, paymentMethod, }: { | ||
intentId: string; | ||
@@ -772,3 +785,2 @@ accessToken?: string | null; | ||
paymentMethod?: PaymentMethodSlugs; | ||
useWalletBalance?: boolean; | ||
}): Promise<IntentDetails<TType>>; | ||
@@ -931,5 +943,6 @@ /** | ||
get lang(): string; | ||
render({ selector, intentId, onHeightChange, }: { | ||
render({ selector, intentId, sandbox, onHeightChange, }: { | ||
selector: string; | ||
intentId: string; | ||
sandbox?: IFrameSandboxOptionsType[]; | ||
onHeightChange?: (iframeHeight: number) => void; | ||
@@ -973,2 +986,3 @@ }): Promise<void>; | ||
loader?: LoaderStyle; | ||
checkout?: CheckoutStyle; | ||
}; | ||
@@ -975,0 +989,0 @@ } |
@@ -36,4 +36,4 @@ var be = Object.defineProperty, ke = Object.defineProperties; | ||
i(t.next(n)); | ||
} catch (c) { | ||
a(c); | ||
} catch (l) { | ||
a(l); | ||
} | ||
@@ -43,4 +43,4 @@ }, d = (n) => { | ||
i(t.throw(n)); | ||
} catch (c) { | ||
a(c); | ||
} catch (l) { | ||
a(l); | ||
} | ||
@@ -50,4 +50,5 @@ }, i = (n) => n.done ? s(n.value) : Promise.resolve(n.value).then(r, d); | ||
}); | ||
import { M as ve, g as he, S as Se, t as g, w as Ce, s as G } from "./warnIf-2fbafbe1.js"; | ||
function Le() { | ||
import { M as ve, g as he, S as Se, t as g, w as Ce, s as O } from "./warnIf-54c1376b.js"; | ||
import { I as He } from "./warnIf-54c1376b.js"; | ||
function Ie() { | ||
return typeof window != "undefined"; | ||
@@ -57,3 +58,3 @@ } | ||
constructor() { | ||
Le() && this.initSDKCommunicationIframe(); | ||
Ie() && this.initSDKCommunicationIframe(); | ||
} | ||
@@ -64,3 +65,3 @@ initSDKCommunicationIframe() { | ||
const e = he(), 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.7.3"); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.8.0"); | ||
const s = document.createElement("iframe"); | ||
@@ -90,6 +91,6 @@ s.id = "moneyhash-headless-sdk", s.src = t.toString(), s.hidden = !0, document.body.appendChild(s), b.messagingService = new ve({ | ||
}); | ||
const d = (c) => { | ||
const d = (l) => { | ||
var u; | ||
const { type: l, data: p } = c.data; | ||
l === e && (p.status === "resolved" ? a(p.payload) : r(p.payload), (u = b.messagingService) == null || u.removeListener(d)); | ||
const { type: c, data: p } = l.data; | ||
c === e && (p.status === "resolved" ? a(p.payload) : r(p.payload), (u = b.messagingService) == null || u.removeListener(d)); | ||
}; | ||
@@ -105,5 +106,5 @@ (n = b.messagingService) == null || n.onReceive(d); | ||
}; | ||
let L = b; | ||
f(L, "messagingService", null), f(L, "isCommunicationReady"); | ||
class O { | ||
let I = b; | ||
f(I, "messagingService", null), f(I, "isCommunicationReady"); | ||
class G { | ||
constructor() { | ||
@@ -118,3 +119,3 @@ f(this, "promise"); | ||
} | ||
function Ie() { | ||
function Le() { | ||
var e; | ||
@@ -172,6 +173,6 @@ return (e = window.MONEYHASH_VAULT_API_URL) != null ? e : "https://vault.moneyhash.io"; | ||
]); | ||
var I, Y, M, B, $, ue, F, me, q, ge, R, x, H, ye, N, fe, D, we, V, Pe; | ||
var L, Y, M, B, $, ue, F, me, q, ge, R, x, H, ye, N, fe, D, we, V, Pe; | ||
class $e { | ||
constructor(e) { | ||
P(this, I); | ||
P(this, L); | ||
P(this, M); | ||
@@ -187,3 +188,3 @@ P(this, $); | ||
f(this, "options"); | ||
f(this, "sdkApiHandler", new L()); | ||
f(this, "sdkApiHandler", new I()); | ||
f(this, "sdkEmbed"); | ||
@@ -216,3 +217,3 @@ f(this, "vaultSubmitListener", { | ||
}), | ||
pay: (i) => m(this, [i], function* ({ | ||
pay: (d) => m(this, [d], function* ({ | ||
intentId: e, | ||
@@ -222,4 +223,3 @@ cardData: t, | ||
billingData: a, | ||
shippingData: r, | ||
useWalletBalance: d | ||
shippingData: r | ||
}) { | ||
@@ -235,3 +235,2 @@ return this.sdkApiHandler.request({ | ||
cardEmbed: t, | ||
useWalletBalance: d, | ||
saveCard: s | ||
@@ -475,3 +474,3 @@ } | ||
*/ | ||
payWithApplePay(c) { | ||
payWithApplePay(l) { | ||
return m(this, arguments, function* ({ | ||
@@ -493,3 +492,3 @@ intentId: e, | ||
return; | ||
const l = new ApplePaySession(3, { | ||
const c = new ApplePaySession(3, { | ||
countryCode: a, | ||
@@ -528,4 +527,4 @@ currencyCode: t, | ||
} | ||
const E = new O(); | ||
l.onvalidatemerchant = (A) => { | ||
const E = new G(); | ||
c.onvalidatemerchant = (A) => { | ||
fetch(`${oe()}/api/v1/providers/applepay/session/`, { | ||
@@ -541,5 +540,5 @@ method: "post", | ||
}).then((k) => k.ok ? k.json() : Promise.reject()).then( | ||
(k) => l.completeMerchantValidation(k) | ||
(k) => c.completeMerchantValidation(k) | ||
).catch(d); | ||
}, l.onpaymentauthorized = (A) => { | ||
}, c.onpaymentauthorized = (A) => { | ||
fetch(`${oe()}/api/v1/providers/applepay/token/`, { | ||
@@ -557,7 +556,7 @@ method: "post", | ||
}).then((k) => k.ok ? k.json() : Promise.reject()).then(() => { | ||
l.completePayment(ApplePaySession.STATUS_SUCCESS), i == null || i(), E.resolve(void 0); | ||
c.completePayment(ApplePaySession.STATUS_SUCCESS), i == null || i(), E.resolve(void 0); | ||
}).catch(() => { | ||
l.completePayment(ApplePaySession.STATUS_FAILURE), d(), E.reject(void 0); | ||
c.completePayment(ApplePaySession.STATUS_FAILURE), d(), E.reject(void 0); | ||
}); | ||
}, l.oncancel = r, l.begin(), yield E.promise; | ||
}, c.oncancel = r, c.begin(), yield E.promise; | ||
}); | ||
@@ -606,6 +605,6 @@ } | ||
}); | ||
const d = y(this, I, Y).call(this); | ||
const d = y(this, L, Y).call(this); | ||
this.googlePaymentsClient.isReadyToPay(d).then((n) => { | ||
if (n.result) { | ||
const c = this.googlePaymentsClient.createButton(_(w({ | ||
const l = this.googlePaymentsClient.createButton(_(w({ | ||
buttonSizeMode: "fill", | ||
@@ -617,3 +616,3 @@ buttonType: "pay" | ||
})); | ||
r == null || r.replaceChildren(c); | ||
r == null || r.replaceChildren(l); | ||
} else | ||
@@ -686,3 +685,3 @@ throw new Error("Google Pay is not ready to pay!"); | ||
const { __nativePayData__: d } = r; | ||
return d ? this.googlePaymentsClient.loadPaymentData(_(w({}, y(this, I, Y).call(this, d)), { | ||
return d ? this.googlePaymentsClient.loadPaymentData(_(w({}, y(this, L, Y).call(this, d)), { | ||
transactionInfo: { | ||
@@ -727,2 +726,3 @@ totalPriceStatus: "FINAL", | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS Selector MDN} | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox | iframe sandbox MDN} | ||
* @returns Promise<void> | ||
@@ -747,8 +747,8 @@ */ | ||
Ce( | ||
!!e && !G.has(e), | ||
`Invalid locale. Supported languages (${[...G].join( | ||
!!e && !O.has(e), | ||
`Invalid locale. Supported languages (${[...O].join( | ||
" | " | ||
)})` | ||
); | ||
const t = G.has(e) ? e : "en"; | ||
const t = O.has(e) ? e : "en"; | ||
return this.sdkEmbed.setLocale(t); | ||
@@ -855,7 +855,7 @@ } | ||
*/ | ||
create: ({ elementType: n, elementOptions: c }) => { | ||
create: ({ elementType: n, elementOptions: l }) => { | ||
var k, K; | ||
const l = /* @__PURE__ */ new Map(); | ||
const c = /* @__PURE__ */ new Map(); | ||
let p = null; | ||
const u = w(w({}, t), c.classes), E = ((k = u == null ? void 0 : u.focus) == null ? void 0 : k.split(" ")) || [ | ||
const u = w(w({}, t), l.classes), E = ((k = u == null ? void 0 : u.focus) == null ? void 0 : k.split(" ")) || [ | ||
"MoneyHashElement--focus" | ||
@@ -868,24 +868,24 @@ ], A = ((K = u == null ? void 0 : u.error) == null ? void 0 : K.split(" ")) || [ | ||
const h = document.querySelector( | ||
c.selector | ||
l.selector | ||
); | ||
g( | ||
!h, | ||
`Couldn't find an element with selector ${c.selector}!` | ||
`Couldn't find an element with selector ${l.selector}!` | ||
), h.classList.add("MoneyHashElement"), a.push((W) => { | ||
var z, J, X, Q, Z, ee, te, ae, ne; | ||
const { type: v, data: S } = W.data; | ||
if (v === `${n}@mount` && (r[n] = S.isValid, (z = l.get(`${n}@mount`)) == null || z()), v === `${n}@focus`) { | ||
h.classList.add(...E), (J = l.get(`${n}@focus`)) == null || J(); | ||
if (v === `${n}@mount` && (r[n] = S.isValid, (z = c.get(`${n}@mount`)) == null || z()), v === `${n}@focus`) { | ||
h.classList.add(...E), (J = c.get(`${n}@focus`)) == null || J(); | ||
return; | ||
} | ||
if (v === `${n}@blur`) { | ||
h.classList.remove(...E), (X = l.get(`${n}@blur`)) == null || X(); | ||
h.classList.remove(...E), (X = c.get(`${n}@blur`)) == null || X(); | ||
return; | ||
} | ||
if (v === `${n}@error`) { | ||
S.isValid ? h.classList.remove(...A) : h.classList.add(...A), (Q = l.get(`${n}@error`)) == null || Q(S); | ||
S.isValid ? h.classList.remove(...A) : h.classList.add(...A), (Q = c.get(`${n}@error`)) == null || Q(S); | ||
return; | ||
} | ||
if (v === `${n}@changeInput`) { | ||
if ((Z = l.get(`${n}@changeInput`)) == null || Z({ | ||
if ((Z = c.get(`${n}@changeInput`)) == null || Z({ | ||
isValid: S.isValid, | ||
@@ -902,3 +902,3 @@ length: S.length | ||
if (v === `${n}@cardNumberChange`) { | ||
(te = l.get(`${n}@cardNumberChange`)) == null || te( | ||
(te = c.get(`${n}@cardNumberChange`)) == null || te( | ||
S | ||
@@ -909,11 +909,11 @@ ); | ||
if (v === `${n}@key:Backspace`) { | ||
(ae = l.get(`${n}@key:Backspace`)) == null || ae(); | ||
(ae = c.get(`${n}@key:Backspace`)) == null || ae(); | ||
return; | ||
} | ||
v === `${n}@key:Enter` && ((ne = l.get(`${n}@key:Enter`)) == null || ne()); | ||
v === `${n}@key:Enter` && ((ne = c.get(`${n}@key:Enter`)) == null || ne()); | ||
}), p = y(this, D, we).call(this, { | ||
container: h, | ||
elementType: n, | ||
elementOptions: c, | ||
styles: w(w({}, e), c.styles), | ||
elementOptions: l, | ||
styles: w(w({}, e), l.styles), | ||
fontSourceCss: s | ||
@@ -923,5 +923,5 @@ }), this.mountedCardElements.push(n); | ||
on: (h, W) => { | ||
l.set(`${n}@${h}`, W); | ||
c.set(`${n}@${h}`, W); | ||
}, | ||
off: (h) => l.delete(`${n}@${h}`), | ||
off: (h) => c.delete(`${n}@${h}`), | ||
focus: () => { | ||
@@ -950,4 +950,4 @@ var h; | ||
}, | ||
on: (n, c) => { | ||
d.set(n, c); | ||
on: (n, l) => { | ||
d.set(n, l); | ||
} | ||
@@ -970,3 +970,3 @@ }; | ||
*/ | ||
submitForm(n) { | ||
submitForm(i) { | ||
return m(this, arguments, function* ({ | ||
@@ -978,14 +978,13 @@ intentId: e, | ||
saveCard: r, | ||
paymentMethod: d = "CARD", | ||
useWalletBalance: i | ||
paymentMethod: d = "CARD" | ||
}) { | ||
let c; | ||
let n; | ||
if (t) { | ||
const p = de( | ||
const c = de( | ||
this.mountedCardElements | ||
); | ||
g( | ||
!!p, | ||
`You must mount ${p} element!` | ||
), c = yield y(this, M, B).call(this, { | ||
!!c, | ||
`You must mount ${c} element!` | ||
), n = yield y(this, M, B).call(this, { | ||
accessToken: t | ||
@@ -1002,4 +1001,3 @@ }); | ||
shippingData: a, | ||
cardEmbed: c, | ||
useWalletBalance: i, | ||
cardEmbed: n, | ||
saveCard: r | ||
@@ -1085,3 +1083,3 @@ } | ||
} | ||
I = new WeakSet(), Y = function(e) { | ||
L = new WeakSet(), Y = function(e) { | ||
var s, a; | ||
@@ -1120,3 +1118,3 @@ return { | ||
return m(this, arguments, function* ({ accessToken: e }) { | ||
const s = new O(); | ||
const s = new G(); | ||
this.vaultSubmitListener.current = (d) => { | ||
@@ -1155,3 +1153,3 @@ const { type: i, data: n } = d.data; | ||
top: n = 200 | ||
} = s.window || {}, c = window.open( | ||
} = s.window || {}, l = window.open( | ||
t, | ||
@@ -1161,3 +1159,3 @@ "", | ||
); | ||
g(!c, "Popup blocked by browser!"), yield y(this, R, x).call(this, { intentId: e, isUsingPopUp: !0 }), c == null || c.close(); | ||
g(!l, "Popup blocked by browser!"), yield y(this, R, x).call(this, { intentId: e, isUsingPopUp: !0 }), l == null || l.close(); | ||
}); | ||
@@ -1180,4 +1178,4 @@ }, q = new WeakSet(), ge = function(s) { | ||
}) { | ||
const a = new O(), r = (d) => m(this, null, function* () { | ||
var n, c, l, p; | ||
const a = new G(), r = (d) => m(this, null, function* () { | ||
var n, l, c, p; | ||
if (d.origin !== he()) | ||
@@ -1192,5 +1190,5 @@ return; | ||
]), E = u.transaction.status.split(".")[1]; | ||
E === "successful" || E.startsWith("pending") ? (c = (n = this.options).onComplete) == null || c.call(n, w({ | ||
E === "successful" || E.startsWith("pending") ? (l = (n = this.options).onComplete) == null || l.call(n, w({ | ||
type: this.options.type | ||
}, u)) : (p = (l = this.options).onFail) == null || p.call(l, w({ | ||
}, u)) : (p = (c = this.options).onFail) == null || p.call(c, w({ | ||
type: this.options.type | ||
@@ -1221,7 +1219,7 @@ }, u)), a.resolve(() => null), window.removeEventListener("message", r); | ||
}) { | ||
var c, l, p, u; | ||
var l, c, p, u; | ||
const d = C(), i = new URL(`${d}/vaultField/vaultField.html`); | ||
r && i.searchParams.set("fontSourceCss", r), i.searchParams.set("host", btoa(window.location.origin)), i.searchParams.set("type", t), ((c = s.validation) == null ? void 0 : c.required) !== void 0 && i.searchParams.set( | ||
r && i.searchParams.set("fontSourceCss", r), i.searchParams.set("host", btoa(window.location.origin)), i.searchParams.set("type", t), ((l = s.validation) == null ? void 0 : l.required) !== void 0 && i.searchParams.set( | ||
"required", | ||
`${(l = s.validation) == null ? void 0 : l.required}` | ||
`${(c = s.validation) == null ? void 0 : c.required}` | ||
), i.searchParams.set("placeholder", (p = s.placeholder) != null ? p : ""), i.searchParams.set("lang", this.sdkEmbed.lang), i.searchParams.set("direction", (a == null ? void 0 : a.direction) || ""), i.searchParams.set( | ||
@@ -1240,3 +1238,3 @@ "color", | ||
}, V = new WeakSet(), Pe = function({ accessToken: e }) { | ||
const t = C(), s = Ie(), a = new URL( | ||
const t = C(), s = Le(), a = new URL( | ||
`${t}/vaultSubmit/vaultSubmit.html` | ||
@@ -1249,3 +1247,4 @@ ); | ||
export { | ||
He as IFrameSandboxOptions, | ||
$e as default | ||
}; |
@@ -1,1 +0,1 @@ | ||
(function(c,d){typeof exports=="object"&&typeof module!="undefined"?module.exports=d():typeof define=="function"&&define.amd?define(d):(c=typeof globalThis!="undefined"?globalThis:c||self,c.MoneyHash=d())})(this,function(){var q,Q,H,Z,j,we,O,be,T,Pe,N,ee,W,ve,B,Ee,G,ke,Y,Ae;"use strict";var Le=Object.defineProperty,Me=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable;var X=(c,d,h)=>d in c?Le(c,d,{enumerable:!0,configurable:!0,writable:!0,value:h}):c[d]=h,k=(c,d)=>{for(var h in d||(d={}))ge.call(d,h)&&X(c,h,d[h]);if(x)for(var h of x(d))ye.call(d,h)&&X(c,h,d[h]);return c},K=(c,d)=>Me(c,Ie(d));var fe=(c,d)=>{var h={};for(var P in c)ge.call(c,P)&&d.indexOf(P)<0&&(h[P]=c[P]);if(c!=null&&x)for(var P of x(c))d.indexOf(P)<0&&ye.call(c,P)&&(h[P]=c[P]);return h};var w=(c,d,h)=>(X(c,typeof d!="symbol"?d+"":d,h),h),Ue=(c,d,h)=>{if(!d.has(c))throw TypeError("Cannot "+h)};var L=(c,d,h)=>{if(d.has(c))throw TypeError("Cannot add the same private member more than once");d instanceof WeakSet?d.add(c):d.set(c,h)};var A=(c,d,h)=>(Ue(c,d,"access private method"),h);var b=(c,d,h)=>new Promise((P,y)=>{var V=R=>{try{$(h.next(R))}catch(F){y(F)}},_=R=>{try{$(h.throw(R))}catch(F){y(F)}},$=R=>R.done?P(R.value):Promise.resolve(R.value).then(V,_);$((h=h.apply(c,d)).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 d(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function h(){return typeof window!="undefined"}const C=class{constructor(){h()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=d(),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.7.3");const a=document.createElement("iframe");a.id="moneyhash-headless-sdk",a.src=t.toString(),a.hidden=!0,document.body.appendChild(a),C.messagingService=new c({target:a.contentWindow,targetOrigin:e}),C.isCommunicationReady=new Promise(s=>{var o;const i=r=>{var n;r.data.type==="headlessSDK:init"&&(s(),(n=C.messagingService)==null||n.removeListener(i))};(o=C.messagingService)==null||o.onReceive(i)})}request(a){return b(this,arguments,function*({api:e,payload:t}){return yield C.isCommunicationReady,new Promise((s,i)=>{var r,n;(r=C.messagingService)==null||r.send({type:e,data:t});const o=p=>{var u;const{type:l,data:m}=p.data;l===e&&(m.status==="resolved"?s(m.payload):i(m.payload),(u=C.messagingService)==null||u.removeListener(o))};(n=C.messagingService)==null||n.onReceive(o)})})}postMessage(e){var t;(t=C.messagingService)==null||t.send({type:e})}};let P=C;w(P,"messagingService",null),w(P,"isCommunicationReady");function y(f,e){if(f)throw new Error(e)}const V=new Set(["payment","payout"]),_=new Set(["en","fr","ar"]);class ${constructor(e){w(this,"options");w(this,"messagingService",null);w(this,"iframe",null);w(this,"isCommunicationReady",null);y(!V.has(e.type),`MoneyHash constructor must be called with valid type (${[...V].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,onHeightChange:a}){var n,p;(n=this.messagingService)==null||n.abortService();const s=d(),i=new URL(`${s}/embed/${this.options.type}/${t}`);i.searchParams.set("sdk","true"),i.searchParams.set("parent",window.location.origin),i.searchParams.set("version","js@1.7.3"),a&&i.searchParams.set("onDimensionsChange","true");const o=(p=this.options.locale)==null?void 0:p.split("-")[0];o&&i.searchParams.set("lang",o),this.iframe=document.createElement("iframe"),this.iframe.src=i.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const r=document.querySelector(e);return y(!r,`Couldn't find an element with selector ${e}!`),r.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:s}),this.isCommunicationReady=new Promise(l=>{var u;const m=v=>{var E;v.data.type==="sdk:init"&&(l(),(E=this.messagingService)==null||E.removeListener(m))};(u=this.messagingService)==null||u.onReceive(m)}),this.messagingService.onReceive((l,m)=>{var E,S,D,g;const{type:u,data:v}=l.data;switch(u){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(S=(E=this.options).onComplete)==null||S.call(E,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(g=(D=this.options).onFail)==null||g.call(D,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{a==null||a(v.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class R{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function F(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function U(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function te(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function se(f){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!f.includes(t))return t;return null}function ie(f){return(Array.isArray(f)?f.length:Object.keys(f).length)===0}function ne(f,e){return new Promise((t,a)=>{if(document.getElementById(e)){t(void 0);return}const i=document.createElement("script");i.src=f,i.id=e,i.addEventListener("load",()=>{t(void 0)}),i.addEventListener("error",()=>{a(new Error("Script failed to load"))}),document.body.appendChild(i)})}function Se(f){return new Promise(e=>{setTimeout(()=>{e("done")},f*1e3)})}function Re(f,e){f&&console.warn(e)}const ae=new Set(["method","customerBalance","savedCard"]);class Ce{constructor(e){L(this,q);L(this,H);L(this,j);L(this,O);L(this,T);L(this,N);L(this,W);L(this,B);L(this,G);L(this,Y);w(this,"options");w(this,"sdkApiHandler",new P);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);w(this,"googlePaymentsClient",null);w(this,"cardForm",{collect:()=>b(this,null,function*(){y(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=se(this.mountedCardElements);y(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,H,Z).call(this,{accessToken:t})}),pay:r=>b(this,[r],function*({intentId:e,cardData:t,saveCard:a,billingData:s,shippingData:i,useWalletBalance:o}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:s,shippingData:i,cardEmbed:t,useWalletBalance:o,saveCard:a}})}),createCardToken:a=>b(this,[a],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new $(K(k({},e),{headless:!0})),A(this,B,Ee).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):(y(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),y(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:k({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:a,useWalletBalance:s,metaData:i}){return y(!ae.has(t),`type must be a valid one (${[...ae].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:a,lang:this.sdkEmbed.lang,useWalletBalance:s,metaData:i}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return y(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(p){return b(this,arguments,function*({intentId:e,currency:t,amount:a,countryCode:s,onCancel:i=()=>{},onError:o,onComplete:r,billingData:n={}}){if(yield ne("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${a}`}}),{state:m,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="FORM_FIELDS"){if(ie(n))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:n}})}}catch(E){throw yield this.resetSelectedMethod(e),E}const v=new R;l.onvalidatemerchant=E=>{fetch(`${te()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:E.validationURL})}).then(S=>S.ok?S.json():Promise.reject()).then(S=>l.completeMerchantValidation(S)).catch(o)},l.onpaymentauthorized=E=>{fetch(`${te()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:E.payment.token},secret:u.secret})}).then(S=>S.ok?S.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),v.resolve(void 0)}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),o(),v.reject(void 0)})},l.oncancel=i,l.begin(),yield v.promise})}renderGooglePayButton(a){return b(this,null,function*(){var s=a,{onClick:e}=s,t=fe(s,["onClick"]);var r;const i=document.getElementById("moneyHash-google-pay-button");y(!i,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ne("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=A(this,q,Q).call(this);this.googlePaymentsClient.isReadyToPay(o).then(n=>{if(n.result){const p=this.googlePaymentsClient.createButton(K(k({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));i==null||i.replaceChildren(p)}else throw new Error("Google Pay is not ready to pay!")}).catch(n=>{console.dir(n)})})}payWithGooglePay(s){return b(this,arguments,function*({intentId:e,billingData:t={},onCancel:a}){y(!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(ie(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.googlePaymentsClient.loadPaymentData(K(k({},A(this,q,Q).call(this,o)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${o.amount}`,currencyCode:o.currency_code,countryCode:o.country_code},merchantInfo:{merchantName:o==null?void 0:o.merchant_name,merchantId:o==null?void 0:o.merchant_id}})).then(r=>{const n=r.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:n}})}).catch(r=>(r.statusCode==="CANCELED"?a==null||a():console.dir(r),Promise.reject(r))):i})}renderForm(e){return y(!e.selector,"selector is required for renderForm"),y(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){Re(!!e&&!_.has(e),`Invalid locale. Supported languages (${[..._].join(" | ")})`);const t=_.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return y(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(a=>{y(!a.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:a}){const s=[],i={},o=new Map;let r=!1;return A(this,W,ve).call(this,s),{create:({elementType:n,elementOptions:p})=>{var S,D;const l=new Map;let m=null;const u=k(k({},t),p.classes),v=((S=u==null?void 0:u.focus)==null?void 0:S.split(" "))||["MoneyHashElement--focus"],E=((D=u==null?void 0:u.error)==null?void 0:D.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(p.selector);y(!g,`Couldn't find an element with selector ${p.selector}!`),g.classList.add("MoneyHashElement"),s.push(z=>{var re,oe,de,ce,le,he,me,pe,ue;const{type:M,data:I}=z.data;if(M===`${n}@mount`&&(i[n]=I.isValid,(re=l.get(`${n}@mount`))==null||re()),M===`${n}@focus`){g.classList.add(...v),(oe=l.get(`${n}@focus`))==null||oe();return}if(M===`${n}@blur`){g.classList.remove(...v),(de=l.get(`${n}@blur`))==null||de();return}if(M===`${n}@error`){I.isValid?g.classList.remove(...E):g.classList.add(...E),(ce=l.get(`${n}@error`))==null||ce(I);return}if(M===`${n}@changeInput`){if((le=l.get(`${n}@changeInput`))==null||le({isValid:I.isValid,length:I.length}),i[n]=I.isValid,o.get("validityChange")){const J=Object.values(i).every(Boolean);J!==r&&((he=o.get("validityChange"))==null||he(J),r=J)}return}if(M===`${n}@cardNumberChange`){(me=l.get(`${n}@cardNumberChange`))==null||me(I);return}if(M===`${n}@key:Backspace`){(pe=l.get(`${n}@key:Backspace`))==null||pe();return}M===`${n}@key:Enter`&&((ue=l.get(`${n}@key:Enter`))==null||ue())}),m=A(this,G,ke).call(this,{container:g,elementType:n,elementOptions:p,styles:k(k({},e),p.styles),fontSourceCss:a}),this.mountedCardElements.push(n)},on:(g,z)=>{l.set(`${n}@${g}`,z)},off:g=>l.delete(`${n}@${g}`),focus:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"focus"},U())},blur:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"blur"},U())},clear:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"clear"},U())}}},on:(n,p)=>{o.set(n,p)}}}submitForm(n){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:a,shippingData:s,saveCard:i,paymentMethod:o="CARD",useWalletBalance:r}){let p;if(t){const m=se(this.mountedCardElements);y(!!m,`You must mount ${m} element!`),p=yield A(this,H,Z).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:a,shippingData:s,cardEmbed:p,useWalletBalance:r,saveCard:i}})})}submitCvv(a){return b(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(i){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:a,options:s}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),a){case"IFRAME":return A(this,j,we).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,O,be).call(this,{url:t,intentId:e,options:s});case"REDIRECT":return A(this,T,Pe).call(this,{url:t,options:s});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const a=new Date(e),s=setInterval(()=>b(this,null,function*(){const i=new Date;a<i&&(clearInterval(s),t())}),1e3);return()=>clearInterval(s)}}return q=new WeakSet,Q=function(e){var a,s;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[k({type:"CARD",parameters:{allowedAuthMethods:((a=this.options.googlePay)==null?void 0:a.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((s=this.options.googlePay)==null?void 0:s.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},H=new WeakSet,Z=function(t){return b(this,arguments,function*({accessToken:e}){const a=new R;this.vaultSubmitListener.current=o=>{const{type:r,data:n}=o.data;r==="vaultSubmit:success"&&a.resolve(n),r==="vaultSubmit:error"&&a.reject(n)};const s=A(this,Y,Ae).call(this,{accessToken:e}),i=yield a.promise;return s.remove(),i})},j=new WeakSet,we=function(a){return b(this,arguments,function*({intentId:e,url:t}){const s=document.querySelector("#rendered-url-iframe-container");y(!s,"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"),s==null||s.replaceChildren(i),yield A(this,N,ee).call(this,{intentId:e}),i.remove()})},O=new WeakSet,be=function(s){return b(this,arguments,function*({intentId:e,url:t,options:a={}}){const{width:i=600,height:o=400,left:r=200,top:n=200}=a.window||{},p=window.open(t,"",`width=${i},height=${o},left=${r},top=${n}`);y(!p,"Popup blocked by browser!"),yield A(this,N,ee).call(this,{intentId:e,isUsingPopUp:!0}),p==null||p.close()})},T=new WeakSet,Pe=function(a){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},N=new WeakSet,ee=function(a){return b(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const s=new R,i=o=>b(this,null,function*(){var n,p,l,m;if(o.origin!==d())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),Se(2)]),v=u.transaction.status.split(".")[1];v==="successful"||v.startsWith("pending")?(p=(n=this.options).onComplete)==null||p.call(n,k({type:this.options.type},u)):(m=(l=this.options).onFail)==null||m.call(l,k({type:this.options.type},u)),s.resolve(()=>null),window.removeEventListener("message",i)}});return window.addEventListener("message",i),s.promise})},W=new WeakSet,ve=function(e){const t=a=>{a.origin===U()&&e.forEach(s=>{s(a)})};window.addEventListener("message",t)},B=new WeakSet,Ee=function(e){const t=a=>{e.current&&e.current(a)};window.addEventListener("message",t)},G=new WeakSet,ke=function({container:e,elementType:t,elementOptions:a,styles:s,fontSourceCss:i}){var p,l,m,u;const o=U(),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),((p=a.validation)==null?void 0:p.required)!==void 0&&r.searchParams.set("required",`${(l=a.validation)==null?void 0:l.required}`),r.searchParams.set("placeholder",(m=a.placeholder)!=null?m:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(s==null?void 0:s.direction)||""),r.searchParams.set("color",JSON.stringify(s!=null&&s.color?s.color:"#000")),r.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(s==null?void 0:s.fontSize)||""),r.searchParams.set("fontFamily",(s==null?void 0:s.fontFamily)||""),r.searchParams.set("fontWeight",`${s==null?void 0:s.fontWeight}`),r.searchParams.set("fontStyle",(s==null?void 0:s.fontStyle)||""),r.searchParams.set("padding",(s==null?void 0:s.padding)||"");const n=document.createElement("iframe");return n.src=r.toString(),n.style.height=(u=s==null?void 0:s.height)!=null?u:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n),n},Y=new WeakSet,Ae=function({accessToken:e}){const t=U(),a=F(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${a}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang);const i=document.createElement("iframe");return i.id="moneyhash-submit-iframe",i.src=s.toString(),i.hidden=!0,document.body.appendChild(i),i},Ce}); | ||
(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,Z,N,ee,j,be,T,ve,W,Pe,D,te,B,Ee,G,ke,Y,Ae,x,Se;"use strict";var Ie=Object.defineProperty,_e=Object.defineProperties;var Ue=Object.getOwnPropertyDescriptors;var K=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var Q=(d,c,l)=>c in d?Ie(d,c,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[c]=l,k=(d,c)=>{for(var l in c||(c={}))ye.call(c,l)&&Q(d,l,c[l]);if(K)for(var l of K(c))fe.call(c,l)&&Q(d,l,c[l]);return d},z=(d,c)=>_e(d,Ue(c));var we=(d,c)=>{var l={};for(var S in d)ye.call(d,S)&&c.indexOf(S)<0&&(l[S]=d[S]);if(d!=null&&K)for(var S of K(d))c.indexOf(S)<0&&fe.call(d,S)&&(l[S]=d[S]);return l};var f=(d,c,l)=>(Q(d,typeof c!="symbol"?c+"":c,l),l),Fe=(d,c,l)=>{if(!c.has(d))throw TypeError("Cannot "+l)};var M=(d,c,l)=>{if(c.has(d))throw TypeError("Cannot add the same private member more than once");c instanceof WeakSet?c.add(d):c.set(d,l)};var A=(d,c,l)=>(Fe(d,c,"access private method"),l);var b=(d,c,l)=>new Promise((S,L)=>{var O=R=>{try{U(l.next(R))}catch(q){L(q)}},w=R=>{try{U(l.throw(R))}catch(q){L(q)}},U=R=>R.done?S(R.value):Promise.resolve(R.value).then(O,w);U((l=l.apply(d,c)).next())});class c{constructor(e){f(this,"target");f(this,"targetOrigin");f(this,"listeners");f(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function l(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function S(){return typeof window!="undefined"}const C=class{constructor(){S()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=l(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.8.0");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),C.messagingService=new c({target:n.contentWindow,targetOrigin:e}),C.isCommunicationReady=new Promise(s=>{var o;const a=r=>{var i;r.data.type==="headlessSDK:init"&&(s(),(i=C.messagingService)==null||i.removeListener(a))};(o=C.messagingService)==null||o.onReceive(a)})}request(n){return b(this,arguments,function*({api:e,payload:t}){return yield C.isCommunicationReady,new Promise((s,a)=>{var r,i;(r=C.messagingService)==null||r.send({type:e,data:t});const o=u=>{var m;const{type:h,data:p}=u.data;h===e&&(p.status==="resolved"?s(p.payload):a(p.payload),(m=C.messagingService)==null||m.removeListener(o))};(i=C.messagingService)==null||i.onReceive(o)})})}postMessage(e){var t;(t=C.messagingService)==null||t.send({type:e})}};let L=C;f(L,"messagingService",null),f(L,"isCommunicationReady");const O=["allow-downloads","allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-storage-access-by-user-activation","allow-top-navigation","allow-top-navigation-by-user-activation"];function w(y,e){if(y)throw new Error(e)}const U=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class q{constructor(e){f(this,"options");f(this,"messagingService",null);f(this,"iframe",null);f(this,"isCommunicationReady",null);w(!U.has(e.type),`MoneyHash constructor must be called with valid type (${[...U].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:s}){var u,h;(u=this.messagingService)==null||u.abortService();const a=l(),o=new URL(`${a}/embed/${this.options.type}/${t}`);o.searchParams.set("sdk","true"),o.searchParams.set("parent",window.location.origin),o.searchParams.set("version","js@1.8.0"),s&&o.searchParams.set("onDimensionsChange","true");const r=(h=this.options.locale)==null?void 0:h.split("-")[0];r&&o.searchParams.set("lang",r),this.iframe=document.createElement("iframe"),this.iframe.src=o.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",n&&n.forEach(p=>{var m;O.includes(p)&&((m=this.iframe)==null||m.sandbox.add(p))});const i=document.querySelector(e);return w(!i,`Couldn't find an element with selector ${e}!`),i.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:a}),this.isCommunicationReady=new Promise(p=>{var P;const m=E=>{var v;E.data.type==="sdk:init"&&(p(),(v=this.messagingService)==null||v.removeListener(m))};(P=this.messagingService)==null||P.onReceive(m)}),this.messagingService.onReceive((p,m)=>{var v,V,g,$;const{type:P,data:E}=p.data;switch(P){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(V=(v=this.options).onComplete)==null||V.call(v,k({type:this.options.type},E)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{($=(g=this.options).onFail)==null||$.call(g,k({type:this.options.type},E)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{s==null||s(E.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class J{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Re(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function F(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function se(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ie(y){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!y.includes(t))return t;return null}function ae(y){return(Array.isArray(y)?y.length:Object.keys(y).length)===0}function ne(y,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=y,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(a)})}function Ce(y){return new Promise(e=>{setTimeout(()=>{e("done")},y*1e3)})}function Me(y,e){y&&console.warn(e)}const re=new Set(["method","customerBalance","savedCard"]);class Le{constructor(e){M(this,H);M(this,N);M(this,j);M(this,T);M(this,W);M(this,D);M(this,B);M(this,G);M(this,Y);M(this,x);f(this,"options");f(this,"sdkApiHandler",new L);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>b(this,null,function*(){w(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=ie(this.mountedCardElements);w(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,N,ee).call(this,{accessToken:t})}),pay:o=>b(this,[o],function*({intentId:e,cardData:t,saveCard:n,billingData:s,shippingData:a}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:s,shippingData:a,cardEmbed:t,saveCard:n}})}),createCardToken:n=>b(this,[n],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new q(z(k({},e),{headless:!0})),A(this,G,ke).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(w(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),w(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:k({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:n,useWalletBalance:s,metaData:a}){return w(!re.has(t),`type must be a valid one (${[...re].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:n,lang:this.sdkEmbed.lang,useWalletBalance:s,metaData:a}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return w(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(u){return b(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:s,onCancel:a=()=>{},onError:o,onComplete:r,billingData:i={}}){if(yield ne("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const h=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${n}`}}),{state:p,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="FORM_FIELDS"){if(ae(i))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:i}})}}catch(E){throw yield this.resetSelectedMethod(e),E}const P=new J;h.onvalidatemerchant=E=>{fetch(`${se()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:E.validationURL})}).then(v=>v.ok?v.json():Promise.reject()).then(v=>h.completeMerchantValidation(v)).catch(o)},h.onpaymentauthorized=E=>{fetch(`${se()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:E.payment.token},secret:m.secret})}).then(v=>v.ok?v.json():Promise.reject()).then(()=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),P.resolve(void 0)}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),o(),P.reject(void 0)})},h.oncancel=a,h.begin(),yield P.promise})}renderGooglePayButton(n){return b(this,null,function*(){var s=n,{onClick:e}=s,t=we(s,["onClick"]);var r;const a=document.getElementById("moneyHash-google-pay-button");w(!a,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ne("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=A(this,H,Z).call(this);this.googlePaymentsClient.isReadyToPay(o).then(i=>{if(i.result){const u=this.googlePaymentsClient.createButton(z(k({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));a==null||a.replaceChildren(u)}else throw new Error("Google Pay is not ready to pay!")}).catch(i=>{console.dir(i)})})}payWithGooglePay(s){return b(this,arguments,function*({intentId:e,billingData:t={},onCancel:n}){w(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');let a=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(a.state==="FORM_FIELDS"){if(ae(t))throw new Error("Billing data is missing while calling payWithGooglePay");a=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(r){throw yield this.resetSelectedMethod(e),r}const{__nativePayData__:o}=a;return o?this.googlePaymentsClient.loadPaymentData(z(k({},A(this,H,Z).call(this,o)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${o.amount}`,currencyCode:o.currency_code,countryCode:o.country_code},merchantInfo:{merchantName:o==null?void 0:o.merchant_name,merchantId:o==null?void 0:o.merchant_id}})).then(r=>{const i=r.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:i}})}).catch(r=>(r.statusCode==="CANCELED"?n==null||n():console.dir(r),Promise.reject(r))):a})}renderForm(e){return w(!e.selector,"selector is required for renderForm"),w(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){Me(!!e&&!R.has(e),`Invalid locale. Supported languages (${[...R].join(" | ")})`);const t=R.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return w(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(n=>{w(!n.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:n}){const s=[],a={},o=new Map;let r=!1;return A(this,B,Ee).call(this,s),{create:({elementType:i,elementOptions:u})=>{var v,V;const h=new Map;let p=null;const m=k(k({},t),u.classes),P=((v=m==null?void 0:m.focus)==null?void 0:v.split(" "))||["MoneyHashElement--focus"],E=((V=m==null?void 0:m.error)==null?void 0:V.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(u.selector);w(!g,`Couldn't find an element with selector ${u.selector}!`),g.classList.add("MoneyHashElement"),s.push($=>{var oe,de,ce,le,he,pe,me,ue,ge;const{type:I,data:_}=$.data;if(I===`${i}@mount`&&(a[i]=_.isValid,(oe=h.get(`${i}@mount`))==null||oe()),I===`${i}@focus`){g.classList.add(...P),(de=h.get(`${i}@focus`))==null||de();return}if(I===`${i}@blur`){g.classList.remove(...P),(ce=h.get(`${i}@blur`))==null||ce();return}if(I===`${i}@error`){_.isValid?g.classList.remove(...E):g.classList.add(...E),(le=h.get(`${i}@error`))==null||le(_);return}if(I===`${i}@changeInput`){if((he=h.get(`${i}@changeInput`))==null||he({isValid:_.isValid,length:_.length}),a[i]=_.isValid,o.get("validityChange")){const X=Object.values(a).every(Boolean);X!==r&&((pe=o.get("validityChange"))==null||pe(X),r=X)}return}if(I===`${i}@cardNumberChange`){(me=h.get(`${i}@cardNumberChange`))==null||me(_);return}if(I===`${i}@key:Backspace`){(ue=h.get(`${i}@key:Backspace`))==null||ue();return}I===`${i}@key:Enter`&&((ge=h.get(`${i}@key:Enter`))==null||ge())}),p=A(this,Y,Ae).call(this,{container:g,elementType:i,elementOptions:u,styles:k(k({},e),u.styles),fontSourceCss:n}),this.mountedCardElements.push(i)},on:(g,$)=>{h.set(`${i}@${g}`,$)},off:g=>h.delete(`${i}@${g}`),focus:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"focus"},F())},blur:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"blur"},F())},clear:()=>{var g;(g=p==null?void 0:p.contentWindow)==null||g.postMessage({type:"clear"},F())}}},on:(i,u)=>{o.set(i,u)}}}submitForm(r){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:s,saveCard:a,paymentMethod:o="CARD"}){let i;if(t){const h=ie(this.mountedCardElements);w(!!h,`You must mount ${h} element!`),i=yield A(this,N,ee).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:n,shippingData:s,cardEmbed:i,saveCard:a}})})}submitCvv(n){return b(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(a){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:n,options:s}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),n){case"IFRAME":return A(this,j,be).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,T,ve).call(this,{url:t,intentId:e,options:s});case"REDIRECT":return A(this,W,Pe).call(this,{url:t,options:s});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const n=new Date(e),s=setInterval(()=>b(this,null,function*(){const a=new Date;n<a&&(clearInterval(s),t())}),1e3);return()=>clearInterval(s)}}H=new WeakSet,Z=function(e){var n,s;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[k({type:"CARD",parameters:{allowedAuthMethods:((n=this.options.googlePay)==null?void 0:n.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((s=this.options.googlePay)==null?void 0:s.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},N=new WeakSet,ee=function(t){return b(this,arguments,function*({accessToken:e}){const n=new J;this.vaultSubmitListener.current=o=>{const{type:r,data:i}=o.data;r==="vaultSubmit:success"&&n.resolve(i),r==="vaultSubmit:error"&&n.reject(i)};const s=A(this,x,Se).call(this,{accessToken:e}),a=yield n.promise;return s.remove(),a})},j=new WeakSet,be=function(n){return b(this,arguments,function*({intentId:e,url:t}){const s=document.querySelector("#rendered-url-iframe-container");w(!s,"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"),s==null||s.replaceChildren(a),yield A(this,D,te).call(this,{intentId:e}),a.remove()})},T=new WeakSet,ve=function(s){return b(this,arguments,function*({intentId:e,url:t,options:n={}}){const{width:a=600,height:o=400,left:r=200,top:i=200}=n.window||{},u=window.open(t,"",`width=${a},height=${o},left=${r},top=${i}`);w(!u,"Popup blocked by browser!"),yield A(this,D,te).call(this,{intentId:e,isUsingPopUp:!0}),u==null||u.close()})},W=new WeakSet,Pe=function(n){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},D=new WeakSet,te=function(n){return b(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const s=new J,a=o=>b(this,null,function*(){var i,u,h,p;if(o.origin!==l())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),Ce(2)]),P=m.transaction.status.split(".")[1];P==="successful"||P.startsWith("pending")?(u=(i=this.options).onComplete)==null||u.call(i,k({type:this.options.type},m)):(p=(h=this.options).onFail)==null||p.call(h,k({type:this.options.type},m)),s.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),s.promise})},B=new WeakSet,Ee=function(e){const t=n=>{n.origin===F()&&e.forEach(s=>{s(n)})};window.addEventListener("message",t)},G=new WeakSet,ke=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},Y=new WeakSet,Ae=function({container:e,elementType:t,elementOptions:n,styles:s,fontSourceCss:a}){var u,h,p,m;const o=F(),r=new URL(`${o}/vaultField/vaultField.html`);a&&r.searchParams.set("fontSourceCss",a),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((u=n.validation)==null?void 0:u.required)!==void 0&&r.searchParams.set("required",`${(h=n.validation)==null?void 0:h.required}`),r.searchParams.set("placeholder",(p=n.placeholder)!=null?p:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(s==null?void 0:s.direction)||""),r.searchParams.set("color",JSON.stringify(s!=null&&s.color?s.color:"#000")),r.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(s==null?void 0:s.fontSize)||""),r.searchParams.set("fontFamily",(s==null?void 0:s.fontFamily)||""),r.searchParams.set("fontWeight",`${s==null?void 0:s.fontWeight}`),r.searchParams.set("fontStyle",(s==null?void 0:s.fontStyle)||""),r.searchParams.set("padding",(s==null?void 0:s.padding)||"");const i=document.createElement("iframe");return i.src=r.toString(),i.style.height=(m=s==null?void 0:s.height)!=null?m:"40px",i.style.setProperty("overflow","hidden","important"),i.style.setProperty("display","block","important"),i.style.setProperty("width","100%","important"),i.style.setProperty("maxWidth","100%","important"),i.style.setProperty("border","0","important"),i.style.setProperty("margin","0","important"),i.style.setProperty("padding","0","important"),i.style.setProperty("userSelect","none","important"),i.style.setProperty("colorScheme","light only","important"),e.replaceChildren(i),i},x=new WeakSet,Se=function({accessToken:e}){const t=F(),n=Re(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${n}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang);const a=document.createElement("iframe");return a.id="moneyhash-submit-iframe",a.src=s.toString(),a.hidden=!0,document.body.appendChild(a),a},d.IFrameSandboxOptions=O,d.default=Le,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var d=Object.defineProperty;var a=(t,e,s)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var n=(t,e,s)=>(a(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-41ece814.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-64307072.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; |
@@ -63,2 +63,11 @@ export declare interface AbstractIntent { | ||
export declare interface CheckoutStyle { | ||
hideAmountSidebar?: boolean; | ||
hideHeader?: boolean; | ||
hideLoaderMessage?: boolean; | ||
hideFormHeaderMessage?: boolean; | ||
hideNavigationToPaymentMethods?: boolean; | ||
formOnly?: boolean; | ||
} | ||
declare type CommonElementOptions = { | ||
@@ -201,2 +210,6 @@ selector: string; | ||
declare const IFrameSandboxOptions: readonly ["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"]; | ||
declare type IFrameSandboxOptionsType = typeof IFrameSandboxOptions[number]; | ||
declare interface InputAllowedStyle { | ||
@@ -282,2 +295,3 @@ height?: number; | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS Selector MDN} | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox | iframe sandbox MDN} | ||
* @returns Promise<void> | ||
@@ -386,5 +400,6 @@ */ | ||
get lang(): string; | ||
render({ selector, intentId, onHeightChange, }: { | ||
render({ selector, intentId, sandbox, onHeightChange, }: { | ||
selector: string; | ||
intentId: string; | ||
sandbox?: IFrameSandboxOptionsType[]; | ||
onHeightChange?: (iframeHeight: number) => void; | ||
@@ -428,2 +443,3 @@ }): Promise<void>; | ||
loader?: LoaderStyle; | ||
checkout?: CheckoutStyle; | ||
}; | ||
@@ -430,0 +446,0 @@ } |
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-2fbafbe1.js"; | ||
import { S as o, t as d, w as u, s as a } from "./warnIf-54c1376b.js"; | ||
class c { | ||
@@ -24,2 +24,3 @@ constructor(e) { | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors | CSS Selector MDN} | ||
* {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox | iframe sandbox MDN} | ||
* @returns Promise<void> | ||
@@ -26,0 +27,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
(function(i,t){typeof exports=="object"&&typeof module!="undefined"?module.exports=t():typeof define=="function"&&define.amd?define(t):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=t())})(this,function(){"use strict";var P=Object.defineProperty;var F=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var w=(i,t,s)=>t in i?P(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s,b=(i,t)=>{for(var s in t||(t={}))U.call(t,s)&&w(i,s,t[s]);if(F)for(var s of F(t))$.call(t,s)&&w(i,s,t[s]);return i};var a=(i,t,s)=>(w(i,typeof t!="symbol"?t+"":t,s),s);var S=(i,t,s)=>new Promise((l,o)=>{var f=n=>{try{h(s.next(n))}catch(e){o(e)}},y=n=>{try{h(s.throw(n))}catch(e){o(e)}},h=n=>n.done?l(n.value):Promise.resolve(n.value).then(f,y);h((s=s.apply(i,t)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(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(r=>r!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(r=>{r(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 s(n,e){if(n)throw new Error(e)}const l=new Set(["payment","payout"]),o=new Set(["en","fr","ar"]);class f{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);s(!l.has(e.type),`MoneyHash constructor must be called with valid type (${[...l].join(" | ")})!`),this.options=e}get lang(){var r;return((r=this.options.locale)==null?void 0:r.split("-")[0])||"en"}render({selector:e,intentId:r,onHeightChange:g}){var I,M;(I=this.messagingService)==null||I.abortService();const R=t(),c=new URL(`${R}/embed/${this.options.type}/${r}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.7.3"),g&&c.searchParams.set("onDimensionsChange","true");const E=(M=this.options.locale)==null?void 0:M.split("-")[0];E&&c.searchParams.set("lang",E),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const L=document.querySelector(e);return s(!L,`Couldn't find an element with selector ${e}!`),L.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:R}),this.isCommunicationReady=new Promise(v=>{var p;const u=d=>{var m;d.data.type==="sdk:init"&&(v(),(m=this.messagingService)==null||m.removeListener(u))};(p=this.messagingService)==null||p.onReceive(u)}),this.messagingService.onReceive((v,u)=>{var m,k,O,C;const{type:p,data:d}=v.data;switch(p){case"sdk:init":{u({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(k=(m=this.options).onComplete)==null||k.call(m,b({type:this.options.type},d)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(O=this.options).onFail)==null||C.call(O,b({type:this.options.type},d)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{g==null||g(d.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return S(this,null,function*(){var r;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(r=this.messagingService)==null||r.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return S(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function y(n,e){n&&console.warn(e)}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new f(e)}start(e){return s(!e.selector,"selector is required for start"),s(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){y(!!e&&!o.has(e),`Invalid locale. Supported languages (${[...o].join(" | ")})`);const r=o.has(e)?e:"en";return this.sdkEmbed.setLocale(r)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h}); | ||
(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var $=Object.defineProperty;var U=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var b=(i,s,t)=>s in i?$(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,S=(i,s)=>{for(var t in s||(s={}))A.call(s,t)&&b(i,t,s[t]);if(U)for(var t of U(s))_.call(s,t)&&b(i,t,s[t]);return i};var o=(i,s,t)=>(b(i,typeof s!="symbol"?s+"":s,t),t);var E=(i,s,t)=>new Promise((l,m)=>{var g=r=>{try{u(t.next(r))}catch(a){m(a)}},v=r=>{try{u(t.throw(r))}catch(a){m(a)}},u=r=>r.done?l(r.value):Promise.resolve(r.value).then(g,v);u((t=t.apply(i,s)).next())});const i=["allow-downloads","allow-forms","allow-modals","allow-orientation-lock","allow-pointer-lock","allow-popups","allow-popups-to-escape-sandbox","allow-presentation","allow-same-origin","allow-scripts","allow-storage-access-by-user-activation","allow-top-navigation","allow-top-navigation-by-user-activation"];class s{constructor(e){o(this,"target");o(this,"targetOrigin");o(this,"listeners");o(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(n=>n!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(n=>{n(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function t(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function l(a,e){if(a)throw new Error(e)}const m=new Set(["payment","payout"]),g=new Set(["en","fr","ar"]);class v{constructor(e){o(this,"options");o(this,"messagingService",null);o(this,"iframe",null);o(this,"isCommunicationReady",null);l(!m.has(e.type),`MoneyHash constructor must be called with valid type (${[...m].join(" | ")})!`),this.options=e}get lang(){var n;return((n=this.options.locale)==null?void 0:n.split("-")[0])||"en"}render({selector:e,intentId:n,sandbox:R,onHeightChange:w}){var M,O;(M=this.messagingService)==null||M.abortService();const I=t(),d=new URL(`${I}/embed/${this.options.type}/${n}`);d.searchParams.set("sdk","true"),d.searchParams.set("parent",window.location.origin),d.searchParams.set("version","js@1.8.0"),w&&d.searchParams.set("onDimensionsChange","true");const L=(O=this.options.locale)==null?void 0:O.split("-")[0];L&&d.searchParams.set("lang",L),this.iframe=document.createElement("iframe"),this.iframe.src=d.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0",R&&R.forEach(h=>{var c;i.includes(h)&&((c=this.iframe)==null||c.sandbox.add(h))});const k=document.querySelector(e);return l(!k,`Couldn't find an element with selector ${e}!`),k.replaceChildren(this.iframe),this.messagingService=new s({target:this.iframe.contentWindow,targetOrigin:I}),this.isCommunicationReady=new Promise(h=>{var y;const c=p=>{var f;p.data.type==="sdk:init"&&(h(),(f=this.messagingService)==null||f.removeListener(c))};(y=this.messagingService)==null||y.onReceive(c)}),this.messagingService.onReceive((h,c)=>{var f,F,C,P;const{type:y,data:p}=h.data;switch(y){case"sdk:init":{c({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(F=(f=this.options).onComplete)==null||F.call(f,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(P=(C=this.options).onFail)==null||P.call(C,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{w==null||w(p.iframeHeight);break}}}),this.isCommunicationReady}setLocale(e){return E(this,null,function*(){var n;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(n=this.messagingService)==null||n.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return E(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function u(a,e){a&&console.warn(e)}class r{constructor(e){o(this,"options");o(this,"sdkEmbed");this.options=e,this.sdkEmbed=new v(e)}start(e){return l(!e.selector,"selector is required for start"),l(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){u(!!e&&!g.has(e),`Invalid locale. Supported languages (${[...g].join(" | ")})`);const n=g.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return r}); |
{ | ||
"name": "@moneyhash/js-sdk", | ||
"version": "1.7.3", | ||
"version": "1.8.0", | ||
"description": "MoneyHash JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
408923
3147