@moneyhash/js-sdk
Advanced tools
Comparing version 1.5.2-beta.5 to 1.5.2
@@ -1,2 +0,2 @@ | ||
"use strict";var de=Object.defineProperty,ce=Object.defineProperties;var le=Object.getOwnPropertyDescriptors;var G=Object.getOwnPropertySymbols;var ue=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var N=(i,e,t)=>e in i?de(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,k=(i,e)=>{for(var t in e||(e={}))ue.call(e,t)&&N(i,t,e[t]);if(G)for(var t of G(e))he.call(e,t)&&N(i,t,e[t]);return i},Q=(i,e)=>ce(i,le(e));var v=(i,e,t)=>(N(i,typeof e!="symbol"?e+"":e,t),t),pe=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)};var b=(i,e,t)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,t)};var E=(i,e,t)=>(pe(i,e,"access private method"),t);var w=(i,e,t)=>new Promise((s,r)=>{var a=n=>{try{o(t.next(n))}catch(l){r(l)}},c=n=>{try{o(t.throw(n))}catch(l){r(l)}},o=n=>n.done?s(n.value):Promise.resolve(n.value).then(a,c);o((t=t.apply(i,e)).next())});const p=require("./warnIf-30544ab3.cjs");function me(){return typeof window!="undefined"}const y=class{constructor(){me()&&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.5.2-beta.5");const s=document.createElement("iframe");s.id="moneyhash-headless-sdk",s.src=t.toString(),s.hidden=!0,document.body.appendChild(s),y.messagingService=new p.MessagingService({target:s.contentWindow,targetOrigin:e}),y.isCommunicationReady=new Promise(r=>{var c;const a=o=>{var n;o.data.type==="headlessSDK:init"&&(r(),(n=y.messagingService)==null||n.removeListener(a))};(c=y.messagingService)==null||c.onReceive(a)})}request(s){return w(this,arguments,function*({api:e,payload:t}){return yield y.isCommunicationReady,new Promise((r,a)=>{var o,n;(o=y.messagingService)==null||o.send({type:e,data:t});const c=l=>{var h;const{type:d,data:u}=l.data;d===e&&(u.status==="resolved"?r(u.payload):a(u.payload),(h=y.messagingService)==null||h.removeListener(c))};(n=y.messagingService)==null||n.onReceive(c)})})}postMessage(e){var t;(t=y.messagingService)==null||t.send({type:e})}};let A=y;v(A,"messagingService",null),v(A,"isCommunicationReady");class X{constructor(){v(this,"promise");v(this,"resolve");v(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function ge(){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 Z(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function fe(i){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!i.includes(t))return t;return null}function we(i){return(Array.isArray(i)?i.length:Object.keys(i).length)===0}function ve(i,e){return new Promise((t,s)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=i,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{s(new Error("Script failed to load"))}),document.body.appendChild(a)})}function ye(i){return new Promise(e=>{setTimeout(()=>{e("done")},i*1e3)})}const ee=new Set(["method","customerBalance","savedCard"]);var U,te,R,re,$,ne,C,H,M,ae,_,ie,F,se,V,oe;class Pe{constructor(e){b(this,U);b(this,R);b(this,$);b(this,C);b(this,M);b(this,_);b(this,F);b(this,V);v(this,"options");v(this,"sdkApiHandler",new A);v(this,"sdkEmbed");v(this,"vaultSubmitListener",{current:null});v(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new p.SDKEmbed(Q(k({},e),{headless:!0})),E(this,_,ie).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:s,metaData:r}){return p.throwIf(!ee.has(t),`type must be a valid one (${[...ee].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:s,lang:this.sdkEmbed.lang,metaData:r}})}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(l){return w(this,arguments,function*({intentId:e,currency:t,amount:s,countryCode:r,onCancel:a=()=>{},onError:c,onComplete:o,billingData:n={}}){if(yield ve("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const d=new ApplePaySession(3,{countryCode:r,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${s}`}}),{state:u,intent:h}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(u==="INTENT_FORM"){if(we(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(m){throw yield this.resetSelectedMethod(e),m}d.onvalidatemerchant=m=>{fetch(`${Z()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:h.secret,validation_url:m.validationURL})}).then(f=>f.ok?f.json():Promise.reject()).then(f=>d.completeMerchantValidation(f)).catch(c)},d.onpaymentauthorized=m=>{fetch(`${Z()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:m.payment.token},secret:h.secret})}).then(f=>f.ok?f.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),o()}).catch(()=>{d.completePayment(ApplePaySession.STATUS_FAILURE),c()})},d.oncancel=a,d.begin()})}renderForm({selector:e,intentId:t}){return p.throwIf(!e,"selector is required for renderForm"),p.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}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(s=>{p.throwIf(!s.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:s}){const r=[],a={},c=new Map;let o=!1;return E(this,M,ae).call(this,r),{create:({elementType:n,elementOptions:l})=>{var D,W;const d=new Map;let u=null,h;const m=k(k({},t),l.classes),f=((D=m==null?void 0:m.focus)==null?void 0:D.split(" "))||["MoneyHashElement--focus"],L=((W=m==null?void 0:m.error)==null?void 0:W.split(" "))||["MoneyHashElement--error"];return{mount:()=>{h=document.querySelector(l.selector),p.throwIf(!h,`Couldn't find an element with selector ${l.selector}!`),h.classList.add("MoneyHashElement"),r.push(g=>{var j,x,B,T,Y,O,z,J,K;const{type:P,data:I}=g.data;if(P===`${n}@mount`&&(a[n]=I.isValid,(j=d.get(`${n}@mount`))==null||j()),P===`${n}@focus`){h.classList.add(...f),(x=d.get(`${n}@focus`))==null||x();return}if(P===`${n}@blur`){h.classList.remove(...f),(B=d.get(`${n}@blur`))==null||B();return}if(P===`${n}@error`){I.isValid?h.classList.remove(...L):h.classList.add(...L),(T=d.get(`${n}@error`))==null||T(I);return}if(P===`${n}@changeInput`){if((Y=d.get(`${n}@changeInput`))==null||Y({isValid:I.isValid,length:I.length}),a[n]=I.isValid,c.get("validityChange")){const q=Object.values(a).every(Boolean);q!==o&&((O=c.get("validityChange"))==null||O(q),o=q)}return}if(P===`${n}@cardNumberChange`){(z=d.get(`${n}@cardNumberChange`))==null||z(I);return}if(P===`${n}@key:Backspace`){(J=d.get(`${n}@key:Backspace`))==null||J();return}P===`${n}@key:Enter`&&((K=d.get(`${n}@key:Enter`))==null||K())}),u=E(this,F,se).call(this,{container:h,elementType:n,elementOptions:l,styles:k(k({},e),l.styles),fontSourceCss:s}),this.mountedCardElements.push(n)},on:(g,P)=>{d.set(`${n}@${g}`,P)},off:g=>d.delete(`${n}@${g}`),focus:()=>{var g;(g=u==null?void 0:u.contentWindow)==null||g.postMessage({type:"focus"},S())},blur:()=>{var g;(g=u==null?void 0:u.contentWindow)==null||g.postMessage({type:"blur"},S())},clear:()=>{var g;(g=u==null?void 0:u.contentWindow)==null||g.postMessage({type:"clear"},S())}}},on:(n,l)=>{c.set(n,l)}}}submitForm(o){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:s,shippingData:r,saveCard:a,paymentMethod:c="CARD"}){const n=new X;let l,d;if(t){const h=fe(this.mountedCardElements);p.throwIf(!!h,`You must mount ${h} element!`),this.vaultSubmitListener.current=m=>{const{type:f,data:L}=m.data;f==="vaultSubmit:success"&&n.resolve(L),f==="vaultSubmit:error"&&n.reject(L)},d=E(this,V,oe).call(this,{accessToken:t,saveCard:a}),l=yield n.promise}const u=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:c,lang:this.sdkEmbed.lang,billingData:s,shippingData:r,cardEmbed:l}});return d&&d.remove(),u})}submitCvv(s){return w(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 w(this,arguments,function*({intentId:e,url:t,renderStrategy:s,options:r}){switch(s){case"IFRAME":return E(this,U,te).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return E(this,R,re).call(this,{url:t,intentId:e,options:r});case"REDIRECT":return E(this,$,ne).call(this,{url:t,options:r});default:return null}})}onExpiration(e,t){if(!e)return p.warnIf(!0,`No expiration date provided!, make sure to check for it before usage | ||
"use strict";var de=Object.defineProperty,ce=Object.defineProperties;var le=Object.getOwnPropertyDescriptors;var G=Object.getOwnPropertySymbols;var ue=Object.prototype.hasOwnProperty,he=Object.prototype.propertyIsEnumerable;var H=(i,e,t)=>e in i?de(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,k=(i,e)=>{for(var t in e||(e={}))ue.call(e,t)&&H(i,t,e[t]);if(G)for(var t of G(e))he.call(e,t)&&H(i,t,e[t]);return i},Q=(i,e)=>ce(i,le(e));var v=(i,e,t)=>(H(i,typeof e!="symbol"?e+"":e,t),t),pe=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)};var E=(i,e,t)=>{if(e.has(i))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(i):e.set(i,t)};var P=(i,e,t)=>(pe(i,e,"access private method"),t);var w=(i,e,t)=>new Promise((s,r)=>{var a=n=>{try{o(t.next(n))}catch(l){r(l)}},c=n=>{try{o(t.throw(n))}catch(l){r(l)}},o=n=>n.done?s(n.value):Promise.resolve(n.value).then(a,c);o((t=t.apply(i,e)).next())});const m=require("./warnIf-24962673.cjs");function me(){return typeof window!="undefined"}const y=class{constructor(){me()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=m.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.5.2");const s=document.createElement("iframe");s.id="moneyhash-headless-sdk",s.src=t.toString(),s.hidden=!0,document.body.appendChild(s),y.messagingService=new m.MessagingService({target:s.contentWindow,targetOrigin:e}),y.isCommunicationReady=new Promise(r=>{var c;const a=o=>{var n;o.data.type==="headlessSDK:init"&&(r(),(n=y.messagingService)==null||n.removeListener(a))};(c=y.messagingService)==null||c.onReceive(a)})}request(s){return w(this,arguments,function*({api:e,payload:t}){return yield y.isCommunicationReady,new Promise((r,a)=>{var o,n;(o=y.messagingService)==null||o.send({type:e,data:t});const c=l=>{var h;const{type:d,data:u}=l.data;d===e&&(u.status==="resolved"?r(u.payload):a(u.payload),(h=y.messagingService)==null||h.removeListener(c))};(n=y.messagingService)==null||n.onReceive(c)})})}postMessage(e){var t;(t=y.messagingService)==null||t.send({type:e})}};let A=y;v(A,"messagingService",null),v(A,"isCommunicationReady");class X{constructor(){v(this,"promise");v(this,"resolve");v(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function ge(){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 Z(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function fe(i){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!i.includes(t))return t;return null}function we(i){return(Array.isArray(i)?i.length:Object.keys(i).length)===0}function ve(i,e){return new Promise((t,s)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=i,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{s(new Error("Script failed to load"))}),document.body.appendChild(a)})}function ye(i){return new Promise(e=>{setTimeout(()=>{e("done")},i*1e3)})}const ee=new Set(["method","customerBalance","savedCard"]);var U,te,R,re,$,ne,C,D,M,ae,_,ie,F,se,V,oe;class Pe{constructor(e){E(this,U);E(this,R);E(this,$);E(this,C);E(this,M);E(this,_);E(this,F);E(this,V);v(this,"options");v(this,"sdkApiHandler",new A);v(this,"sdkEmbed");v(this,"vaultSubmitListener",{current:null});v(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new m.SDKEmbed(Q(k({},e),{headless:!0})),P(this,_,ie).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:s,metaData:r}){return m.throwIf(!ee.has(t),`type must be a valid one (${[...ee].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:s,lang:this.sdkEmbed.lang,metaData:r}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return m.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 w(this,arguments,function*({intentId:e,currency:t,amount:s,countryCode:r,onCancel:a=()=>{},onError:c,onComplete:o,billingData:n={}}){if(yield ve("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const d=new ApplePaySession(3,{countryCode:r,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${s}`}}),{state:u,intent:h}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(u==="INTENT_FORM"){if(we(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(g){throw yield this.resetSelectedMethod(e),g}d.onvalidatemerchant=g=>{fetch(`${Z()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:h.secret,validation_url:g.validationURL})}).then(f=>f.ok?f.json():Promise.reject()).then(f=>d.completeMerchantValidation(f)).catch(c)},d.onpaymentauthorized=g=>{fetch(`${Z()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:g.payment.token},secret:h.secret})}).then(f=>f.ok?f.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),o()}).catch(()=>{d.completePayment(ApplePaySession.STATUS_FAILURE),c()})},d.oncancel=a,d.begin()})}renderForm({selector:e,intentId:t}){return m.throwIf(!e,"selector is required for renderForm"),m.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){m.warnIf(!!e&&!m.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...m.supportedLanguages].join(" | ")})`);const t=m.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return m.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(s=>{m.throwIf(!s.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:s}){const r=[],a={},c=new Map;let o=!1;return P(this,M,ae).call(this,r),{create:({elementType:n,elementOptions:l})=>{var L,W;const d=new Map;let u=null;const h=k(k({},t),l.classes),g=((L=h==null?void 0:h.focus)==null?void 0:L.split(" "))||["MoneyHashElement--focus"],f=((W=h==null?void 0:h.error)==null?void 0:W.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const p=document.querySelector(l.selector);m.throwIf(!p,`Couldn't find an element with selector ${l.selector}!`),p.classList.add("MoneyHashElement"),r.push(q=>{var j,x,B,T,Y,O,z,J,K;const{type:b,data:I}=q.data;if(b===`${n}@mount`&&(a[n]=I.isValid,(j=d.get(`${n}@mount`))==null||j()),b===`${n}@focus`){p.classList.add(...g),(x=d.get(`${n}@focus`))==null||x();return}if(b===`${n}@blur`){p.classList.remove(...g),(B=d.get(`${n}@blur`))==null||B();return}if(b===`${n}@error`){I.isValid?p.classList.remove(...f):p.classList.add(...f),(T=d.get(`${n}@error`))==null||T(I);return}if(b===`${n}@changeInput`){if((Y=d.get(`${n}@changeInput`))==null||Y({isValid:I.isValid,length:I.length}),a[n]=I.isValid,c.get("validityChange")){const N=Object.values(a).every(Boolean);N!==o&&((O=c.get("validityChange"))==null||O(N),o=N)}return}if(b===`${n}@cardNumberChange`){(z=d.get(`${n}@cardNumberChange`))==null||z(I);return}if(b===`${n}@key:Backspace`){(J=d.get(`${n}@key:Backspace`))==null||J();return}b===`${n}@key:Enter`&&((K=d.get(`${n}@key:Enter`))==null||K())}),u=P(this,F,se).call(this,{container:p,elementType:n,elementOptions:l,styles:k(k({},e),l.styles),fontSourceCss:s}),this.mountedCardElements.push(n)},on:(p,q)=>{d.set(`${n}@${p}`,q)},off:p=>d.delete(`${n}@${p}`),focus:()=>{var p;(p=u==null?void 0:u.contentWindow)==null||p.postMessage({type:"focus"},S())},blur:()=>{var p;(p=u==null?void 0:u.contentWindow)==null||p.postMessage({type:"blur"},S())},clear:()=>{var p;(p=u==null?void 0:u.contentWindow)==null||p.postMessage({type:"clear"},S())}}},on:(n,l)=>{c.set(n,l)}}}submitForm(o){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:s,shippingData:r,saveCard:a,paymentMethod:c="CARD"}){const n=new X;let l,d;if(t){const h=fe(this.mountedCardElements);m.throwIf(!!h,`You must mount ${h} element!`),this.vaultSubmitListener.current=g=>{const{type:f,data:L}=g.data;f==="vaultSubmit:success"&&n.resolve(L),f==="vaultSubmit:error"&&n.reject(L)},d=P(this,V,oe).call(this,{accessToken:t,saveCard:a}),l=yield n.promise}const u=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:c,lang:this.sdkEmbed.lang,billingData:s,shippingData:r,cardEmbed:l}});return d&&d.remove(),u})}submitCvv(s){return w(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 w(this,arguments,function*({intentId:e,url:t,renderStrategy:s,options:r}){switch(s){case"IFRAME":return P(this,U,te).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return P(this,R,re).call(this,{url:t,intentId:e,options:r});case"REDIRECT":return P(this,$,ne).call(this,{url:t,options:r});default:return null}})}onExpiration(e,t){if(!e)return m.warnIf(!0,`No expiration date provided!, make sure to check for it before usage | ||
@@ -7,2 +7,2 @@ if (intentDetails.intent.expirationDate) { | ||
}) | ||
}`),()=>{};const s=new Date(e),r=setInterval(()=>w(this,null,function*(){const a=new Date;s<a&&(clearInterval(r),t())}),1e3);return()=>clearInterval(r)}}U=new WeakSet,te=function(s){return w(this,arguments,function*({intentId:e,url:t}){const r=document.querySelector("#rendered-url-iframe-container");p.throwIf(!r,"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"),r==null||r.replaceChildren(a),yield E(this,C,H).call(this,{intentId:e}),a.remove()})},R=new WeakSet,re=function(r){return w(this,arguments,function*({intentId:e,url:t,options:s={}}){const{width:a=600,height:c=400,left:o=200,top:n=200}=s.window||{},l=window.open(t,"",`width=${a},height=${c},left=${o},top=${n}`);p.throwIf(!l,"Popup blocked by browser!"),yield E(this,C,H).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},$=new WeakSet,ne=function(s){return w(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},C=new WeakSet,H=function(s){return w(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const r=new X,a=c=>w(this,null,function*(){var n,l,d,u;if(c.origin!==p.getIframeUrl())return;const{type:o}=c.data;if(o==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[h]=yield Promise.all([this.getIntentDetails(e),ye(2)]),m=h.transaction.status.split(".")[1];m==="successful"||m.startsWith("pending")?(l=(n=this.options).onComplete)==null||l.call(n,k({type:this.options.type},h)):(u=(d=this.options).onFail)==null||u.call(d,k({type:this.options.type},h)),r.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),r.promise})},M=new WeakSet,ae=function(e){const t=s=>{s.origin===S()&&e.forEach(r=>{r(s)})};window.addEventListener("message",t)},_=new WeakSet,ie=function(e){const t=s=>{e.current&&e.current(s)};window.addEventListener("message",t)},F=new WeakSet,se=function({container:e,elementType:t,elementOptions:s,styles:r,fontSourceCss:a}){var l,d,u,h;const c=S(),o=new URL(`${c}/vaultField/vaultField.html`);a&&o.searchParams.set("fontSourceCss",a),o.searchParams.set("host",btoa(window.location.origin)),o.searchParams.set("type",t),((l=s.validation)==null?void 0:l.required)!==void 0&&o.searchParams.set("required",`${(d=s.validation)==null?void 0:d.required}`),o.searchParams.set("placeholder",(u=s.placeholder)!=null?u:""),o.searchParams.set("lang",this.sdkEmbed.lang),o.searchParams.set("direction",(r==null?void 0:r.direction)||""),o.searchParams.set("color",JSON.stringify(r!=null&&r.color?r.color:"#000")),o.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),o.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),o.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),o.searchParams.set("fontFamily",(r==null?void 0:r.fontFamily)||""),o.searchParams.set("fontWeight",`${r==null?void 0:r.fontWeight}`),o.searchParams.set("fontStyle",(r==null?void 0:r.fontStyle)||""),o.searchParams.set("padding",(r==null?void 0:r.padding)||"");const n=document.createElement("iframe");return n.src=o.toString(),n.style.height=(h=r==null?void 0:r.height)!=null?h:"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,oe=function({accessToken:e,saveCard:t}){const s=S(),r=ge(),a=new URL(`${s}/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),t!==void 0&&a.searchParams.set("save_card",`${t}`);const c=document.createElement("iframe");return c.id="moneyhash-submit-iframe",c.src=a.toString(),c.hidden=!0,document.body.appendChild(c),c};module.exports=Pe; | ||
}`),()=>{};const s=new Date(e),r=setInterval(()=>w(this,null,function*(){const a=new Date;s<a&&(clearInterval(r),t())}),1e3);return()=>clearInterval(r)}}U=new WeakSet,te=function(s){return w(this,arguments,function*({intentId:e,url:t}){const r=document.querySelector("#rendered-url-iframe-container");m.throwIf(!r,"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"),r==null||r.replaceChildren(a),yield P(this,C,D).call(this,{intentId:e}),a.remove()})},R=new WeakSet,re=function(r){return w(this,arguments,function*({intentId:e,url:t,options:s={}}){const{width:a=600,height:c=400,left:o=200,top:n=200}=s.window||{},l=window.open(t,"",`width=${a},height=${c},left=${o},top=${n}`);m.throwIf(!l,"Popup blocked by browser!"),yield P(this,C,D).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},$=new WeakSet,ne=function(s){return w(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},C=new WeakSet,D=function(s){return w(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const r=new X,a=c=>w(this,null,function*(){var n,l,d,u;if(c.origin!==m.getIframeUrl())return;const{type:o}=c.data;if(o==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[h]=yield Promise.all([this.getIntentDetails(e),ye(2)]),g=h.transaction.status.split(".")[1];g==="successful"||g.startsWith("pending")?(l=(n=this.options).onComplete)==null||l.call(n,k({type:this.options.type},h)):(u=(d=this.options).onFail)==null||u.call(d,k({type:this.options.type},h)),r.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),r.promise})},M=new WeakSet,ae=function(e){const t=s=>{s.origin===S()&&e.forEach(r=>{r(s)})};window.addEventListener("message",t)},_=new WeakSet,ie=function(e){const t=s=>{e.current&&e.current(s)};window.addEventListener("message",t)},F=new WeakSet,se=function({container:e,elementType:t,elementOptions:s,styles:r,fontSourceCss:a}){var l,d,u,h;const c=S(),o=new URL(`${c}/vaultField/vaultField.html`);a&&o.searchParams.set("fontSourceCss",a),o.searchParams.set("host",btoa(window.location.origin)),o.searchParams.set("type",t),((l=s.validation)==null?void 0:l.required)!==void 0&&o.searchParams.set("required",`${(d=s.validation)==null?void 0:d.required}`),o.searchParams.set("placeholder",(u=s.placeholder)!=null?u:""),o.searchParams.set("lang",this.sdkEmbed.lang),o.searchParams.set("direction",(r==null?void 0:r.direction)||""),o.searchParams.set("color",JSON.stringify(r!=null&&r.color?r.color:"#000")),o.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),o.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),o.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),o.searchParams.set("fontFamily",(r==null?void 0:r.fontFamily)||""),o.searchParams.set("fontWeight",`${r==null?void 0:r.fontWeight}`),o.searchParams.set("fontStyle",(r==null?void 0:r.fontStyle)||""),o.searchParams.set("padding",(r==null?void 0:r.padding)||"");const n=document.createElement("iframe");return n.src=o.toString(),n.style.height=(h=r==null?void 0:r.height)!=null?h:"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,oe=function({accessToken:e,saveCard:t}){const s=S(),r=ge(),a=new URL(`${s}/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),t!==void 0&&a.searchParams.set("save_card",`${t}`);const c=document.createElement("iframe");return c.id="moneyhash-submit-iframe",c.src=a.toString(),c.hidden=!0,document.body.appendChild(c),c};module.exports=Pe; |
@@ -5,15 +5,15 @@ var ue = Object.defineProperty, pe = Object.defineProperties; | ||
var me = Object.prototype.hasOwnProperty, ge = Object.prototype.propertyIsEnumerable; | ||
var q = (i, e, t) => e in i ? ue(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, k = (i, e) => { | ||
var H = (i, e, t) => e in i ? ue(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, k = (i, e) => { | ||
for (var t in e || (e = {})) | ||
me.call(e, t) && q(i, t, e[t]); | ||
me.call(e, t) && H(i, t, e[t]); | ||
if (Q) | ||
for (var t of Q(e)) | ||
ge.call(e, t) && q(i, t, e[t]); | ||
ge.call(e, t) && H(i, t, e[t]); | ||
return i; | ||
}, X = (i, e) => pe(i, he(e)); | ||
var v = (i, e, t) => (q(i, typeof e != "symbol" ? e + "" : e, t), t), fe = (i, e, t) => { | ||
var v = (i, e, t) => (H(i, typeof e != "symbol" ? e + "" : e, t), t), fe = (i, e, t) => { | ||
if (!e.has(i)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var b = (i, e, t) => { | ||
var E = (i, e, t) => { | ||
if (e.has(i)) | ||
@@ -23,3 +23,3 @@ throw TypeError("Cannot add the same private member more than once"); | ||
}; | ||
var P = (i, e, t) => (fe(i, e, "access private method"), t); | ||
var y = (i, e, t) => (fe(i, e, "access private method"), t); | ||
var f = (i, e, t) => new Promise((s, r) => { | ||
@@ -41,3 +41,3 @@ var n = (a) => { | ||
}); | ||
import { M as ve, g as ae, S as we, t as E, w as Z, s as H } from "./warnIf-6b9dc7c7.js"; | ||
import { M as ve, g as ae, S as we, t as P, w as Z, s as D } from "./warnIf-d62a2abd.js"; | ||
function ye() { | ||
@@ -54,3 +54,3 @@ return typeof window != "undefined"; | ||
const e = ae(), 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.5.2-beta.5"); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.5.2"); | ||
const s = document.createElement("iframe"); | ||
@@ -159,13 +159,13 @@ s.id = "moneyhash-headless-sdk", s.src = t.toString(), s.hidden = !0, document.body.appendChild(s), w.messagingService = new ve({ | ||
]); | ||
var U, ne, R, ie, $, se, C, D, M, oe, _, de, F, ce, V, le; | ||
var U, ne, R, ie, $, se, C, W, M, oe, _, de, F, ce, V, le; | ||
class Ce { | ||
constructor(e) { | ||
b(this, U); | ||
b(this, R); | ||
b(this, $); | ||
b(this, C); | ||
b(this, M); | ||
b(this, _); | ||
b(this, F); | ||
b(this, V); | ||
E(this, U); | ||
E(this, R); | ||
E(this, $); | ||
E(this, C); | ||
E(this, M); | ||
E(this, _); | ||
E(this, F); | ||
E(this, V); | ||
v(this, "options"); | ||
@@ -178,3 +178,3 @@ v(this, "sdkApiHandler", new I()); | ||
v(this, "mountedCardElements", []); | ||
this.options = e, this.sdkEmbed = new we(X(k({}, e), { headless: !0 })), P(this, _, de).call(this, this.vaultSubmitListener); | ||
this.options = e, this.sdkEmbed = new we(X(k({}, e), { headless: !0 })), y(this, _, de).call(this, this.vaultSubmitListener); | ||
} | ||
@@ -273,3 +273,3 @@ /** | ||
}) { | ||
return E( | ||
return P( | ||
!re.has(t), | ||
@@ -333,3 +333,3 @@ `type must be a valid one (${[...re].join( | ||
}) { | ||
return E( | ||
return P( | ||
this.options.type === "payout", | ||
@@ -432,6 +432,6 @@ "deleteCard is allowed only for payment intent!" | ||
} | ||
} catch (h) { | ||
throw yield this.resetSelectedMethod(e), h; | ||
} catch (m) { | ||
throw yield this.resetSelectedMethod(e), m; | ||
} | ||
d.onvalidatemerchant = (h) => { | ||
d.onvalidatemerchant = (m) => { | ||
fetch(`${te()}/api/v1/providers/applepay/session/`, { | ||
@@ -444,3 +444,3 @@ method: "post", | ||
secret: p.secret, | ||
validation_url: h.validationURL | ||
validation_url: m.validationURL | ||
}) | ||
@@ -450,3 +450,3 @@ }).then((g) => g.ok ? g.json() : Promise.reject()).then( | ||
).catch(c); | ||
}, d.onpaymentauthorized = (h) => { | ||
}, d.onpaymentauthorized = (m) => { | ||
fetch(`${te()}/api/v1/providers/applepay/token/`, { | ||
@@ -459,3 +459,3 @@ method: "post", | ||
token_data: { | ||
token: h.payment.token | ||
token: m.payment.token | ||
}, | ||
@@ -489,3 +489,3 @@ secret: p.secret | ||
renderForm({ selector: e, intentId: t }) { | ||
return E(!e, "selector is required for renderForm"), E(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t }); | ||
return P(!e, "selector is required for renderForm"), P(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t }); | ||
} | ||
@@ -506,8 +506,8 @@ /** | ||
Z( | ||
!!e && !H.has(e), | ||
`Invalid locale. Supported languages (${[...H].join( | ||
!!e && !D.has(e), | ||
`Invalid locale. Supported languages (${[...D].join( | ||
" | " | ||
)})` | ||
); | ||
const t = H.has(e) ? e : "en"; | ||
const t = D.has(e) ? e : "en"; | ||
return this.sdkEmbed.setLocale(t); | ||
@@ -541,3 +541,3 @@ } | ||
}) { | ||
return E(!t.title.en, "English discount title is required!"), this.sdkApiHandler.request({ | ||
return P(!t.title.en, "English discount title is required!"), this.sdkApiHandler.request({ | ||
api: "sdk:updateIntentDiscount", | ||
@@ -568,3 +568,3 @@ payload: { | ||
return t.forEach((s) => { | ||
E(!s.title.en, "English fee title is required!"); | ||
P(!s.title.en, "English fee title is required!"); | ||
}), this.sdkApiHandler.request({ | ||
@@ -594,3 +594,3 @@ api: "sdk:updateIntentFees", | ||
let o = !1; | ||
return P(this, M, oe).call(this, r), { | ||
return y(this, M, oe).call(this, r), { | ||
/** | ||
@@ -618,8 +618,8 @@ * Creates card field element | ||
create: ({ elementType: a, elementOptions: l }) => { | ||
var W, j; | ||
var L, j; | ||
const d = /* @__PURE__ */ new Map(); | ||
let u = null, p; | ||
const h = k(k({}, t), l.classes), g = ((W = h == null ? void 0 : h.focus) == null ? void 0 : W.split(" ")) || [ | ||
let u = null; | ||
const p = k(k({}, t), l.classes), m = ((L = p == null ? void 0 : p.focus) == null ? void 0 : L.split(" ")) || [ | ||
"MoneyHashElement--focus" | ||
], L = ((j = h == null ? void 0 : h.error) == null ? void 0 : j.split(" ")) || [ | ||
], g = ((j = p == null ? void 0 : p.error) == null ? void 0 : j.split(" ")) || [ | ||
"MoneyHashElement--error" | ||
@@ -629,23 +629,24 @@ ]; | ||
mount: () => { | ||
p = document.querySelector( | ||
const h = document.querySelector( | ||
l.selector | ||
), E( | ||
!p, | ||
); | ||
P( | ||
!h, | ||
`Couldn't find an element with selector ${l.selector}!` | ||
), p.classList.add("MoneyHashElement"), r.push((m) => { | ||
), h.classList.add("MoneyHashElement"), r.push((N) => { | ||
var x, B, T, Y, O, z, J, K, G; | ||
const { type: y, data: S } = m.data; | ||
if (y === `${a}@mount` && (n[a] = S.isValid, (x = d.get(`${a}@mount`)) == null || x()), y === `${a}@focus`) { | ||
p.classList.add(...g), (B = d.get(`${a}@focus`)) == null || B(); | ||
const { type: b, data: S } = N.data; | ||
if (b === `${a}@mount` && (n[a] = S.isValid, (x = d.get(`${a}@mount`)) == null || x()), b === `${a}@focus`) { | ||
h.classList.add(...m), (B = d.get(`${a}@focus`)) == null || B(); | ||
return; | ||
} | ||
if (y === `${a}@blur`) { | ||
p.classList.remove(...g), (T = d.get(`${a}@blur`)) == null || T(); | ||
if (b === `${a}@blur`) { | ||
h.classList.remove(...m), (T = d.get(`${a}@blur`)) == null || T(); | ||
return; | ||
} | ||
if (y === `${a}@error`) { | ||
S.isValid ? p.classList.remove(...L) : p.classList.add(...L), (Y = d.get(`${a}@error`)) == null || Y(S); | ||
if (b === `${a}@error`) { | ||
S.isValid ? h.classList.remove(...g) : h.classList.add(...g), (Y = d.get(`${a}@error`)) == null || Y(S); | ||
return; | ||
} | ||
if (y === `${a}@changeInput`) { | ||
if (b === `${a}@changeInput`) { | ||
if ((O = d.get(`${a}@changeInput`)) == null || O({ | ||
@@ -655,10 +656,10 @@ isValid: S.isValid, | ||
}), n[a] = S.isValid, c.get("validityChange")) { | ||
const N = Object.values(n).every(Boolean); | ||
N !== o && ((z = c.get("validityChange")) == null || z( | ||
N | ||
), o = N); | ||
const q = Object.values(n).every(Boolean); | ||
q !== o && ((z = c.get("validityChange")) == null || z( | ||
q | ||
), o = q); | ||
} | ||
return; | ||
} | ||
if (y === `${a}@cardNumberChange`) { | ||
if (b === `${a}@cardNumberChange`) { | ||
(J = d.get(`${a}@cardNumberChange`)) == null || J( | ||
@@ -669,9 +670,9 @@ S | ||
} | ||
if (y === `${a}@key:Backspace`) { | ||
if (b === `${a}@key:Backspace`) { | ||
(K = d.get(`${a}@key:Backspace`)) == null || K(); | ||
return; | ||
} | ||
y === `${a}@key:Enter` && ((G = d.get(`${a}@key:Enter`)) == null || G()); | ||
}), u = P(this, F, ce).call(this, { | ||
container: p, | ||
b === `${a}@key:Enter` && ((G = d.get(`${a}@key:Enter`)) == null || G()); | ||
}), u = y(this, F, ce).call(this, { | ||
container: h, | ||
elementType: a, | ||
@@ -683,9 +684,9 @@ elementOptions: l, | ||
}, | ||
on: (m, y) => { | ||
d.set(`${a}@${m}`, y); | ||
on: (h, N) => { | ||
d.set(`${a}@${h}`, N); | ||
}, | ||
off: (m) => d.delete(`${a}@${m}`), | ||
off: (h) => d.delete(`${a}@${h}`), | ||
focus: () => { | ||
var m; | ||
(m = u == null ? void 0 : u.contentWindow) == null || m.postMessage( | ||
var h; | ||
(h = u == null ? void 0 : u.contentWindow) == null || h.postMessage( | ||
{ type: "focus" }, | ||
@@ -696,4 +697,4 @@ A() | ||
blur: () => { | ||
var m; | ||
(m = u == null ? void 0 : u.contentWindow) == null || m.postMessage( | ||
var h; | ||
(h = u == null ? void 0 : u.contentWindow) == null || h.postMessage( | ||
{ type: "blur" }, | ||
@@ -704,4 +705,4 @@ A() | ||
clear: () => { | ||
var m; | ||
(m = u == null ? void 0 : u.contentWindow) == null || m.postMessage( | ||
var h; | ||
(h = u == null ? void 0 : u.contentWindow) == null || h.postMessage( | ||
{ type: "clear" }, | ||
@@ -747,9 +748,9 @@ A() | ||
); | ||
E( | ||
P( | ||
!!p, | ||
`You must mount ${p} element!` | ||
), this.vaultSubmitListener.current = (h) => { | ||
const { type: g, data: L } = h.data; | ||
), this.vaultSubmitListener.current = (m) => { | ||
const { type: g, data: L } = m.data; | ||
g === "vaultSubmit:success" && a.resolve(L), g === "vaultSubmit:error" && a.reject(L); | ||
}, d = P(this, V, le).call(this, { accessToken: t, saveCard: n }), l = yield a.promise; | ||
}, d = y(this, V, le).call(this, { accessToken: t, saveCard: n }), l = yield a.promise; | ||
} | ||
@@ -813,7 +814,7 @@ const u = yield this.sdkApiHandler.request({ | ||
case "IFRAME": | ||
return P(this, U, ne).call(this, { url: t, intentId: e }); | ||
return y(this, U, ne).call(this, { url: t, intentId: e }); | ||
case "POPUP_IFRAME": | ||
return P(this, R, ie).call(this, { url: t, intentId: e, options: r }); | ||
return y(this, R, ie).call(this, { url: t, intentId: e, options: r }); | ||
case "REDIRECT": | ||
return P(this, $, se).call(this, { url: t, options: r }); | ||
return y(this, $, se).call(this, { url: t, options: r }); | ||
default: | ||
@@ -861,3 +862,3 @@ return null; | ||
const r = document.querySelector("#rendered-url-iframe-container"); | ||
E( | ||
P( | ||
!r, | ||
@@ -867,3 +868,3 @@ "Couldn't find an element with id rendered-url-iframe-container to render the iframe!" | ||
const n = document.createElement("iframe"); | ||
n.src = t, n.style.setProperty("border", "0", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("height", "100%", "important"), r == null || r.replaceChildren(n), yield P(this, C, D).call(this, { intentId: e }), n.remove(); | ||
n.src = t, n.style.setProperty("border", "0", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("height", "100%", "important"), r == null || r.replaceChildren(n), yield y(this, C, W).call(this, { intentId: e }), n.remove(); | ||
}); | ||
@@ -886,3 +887,3 @@ }, R = new WeakSet(), ie = function(r) { | ||
); | ||
E(!l, "Popup blocked by browser!"), yield P(this, C, D).call(this, { intentId: e, isUsingPopUp: !0 }), l == null || l.close(); | ||
P(!l, "Popup blocked by browser!"), yield y(this, C, W).call(this, { intentId: e, isUsingPopUp: !0 }), l == null || l.close(); | ||
}); | ||
@@ -900,3 +901,3 @@ }, $ = new WeakSet(), se = function(s) { | ||
}); | ||
}, C = new WeakSet(), D = function(s) { | ||
}, C = new WeakSet(), W = function(s) { | ||
return f(this, arguments, function* ({ | ||
@@ -916,4 +917,4 @@ intentId: e, | ||
Se(2) | ||
]), h = p.transaction.status.split(".")[1]; | ||
h === "successful" || h.startsWith("pending") ? (l = (a = this.options).onComplete) == null || l.call(a, k({ | ||
]), m = p.transaction.status.split(".")[1]; | ||
m === "successful" || m.startsWith("pending") ? (l = (a = this.options).onComplete) == null || l.call(a, k({ | ||
type: this.options.type | ||
@@ -920,0 +921,0 @@ }, p)) : (u = (d = this.options).onFail) == null || u.call(d, k({ |
@@ -1,2 +0,2 @@ | ||
(function(m,a){typeof exports=="object"&&typeof module!="undefined"?module.exports=a():typeof define=="function"&&define.amd?define(a):(m=typeof globalThis!="undefined"?globalThis:m||self,m.MoneyHash=a())})(this,function(){var q,ce,j,le,D,he,H,z,W,me,x,ue,B,pe,O,ge;"use strict";var Ee=Object.defineProperty,Pe=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var oe=Object.getOwnPropertySymbols;var Se=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var Y=(m,a,p)=>a in m?Ee(m,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):m[a]=p,L=(m,a)=>{for(var p in a||(a={}))Se.call(a,p)&&Y(m,p,a[p]);if(oe)for(var p of oe(a))Le.call(a,p)&&Y(m,p,a[p]);return m},de=(m,a)=>Pe(m,ke(a));var y=(m,a,p)=>(Y(m,typeof a!="symbol"?a+"":a,p),p),Ae=(m,a,p)=>{if(!a.has(m))throw TypeError("Cannot "+p)};var R=(m,a,p)=>{if(a.has(m))throw TypeError("Cannot add the same private member more than once");a instanceof WeakSet?a.add(m):a.set(m,p)};var A=(m,a,p)=>(Ae(m,a,"access private method"),p);var E=(m,a,p)=>new Promise((C,w)=>{var V=k=>{try{_(p.next(k))}catch(F){w(F)}},$=k=>{try{_(p.throw(k))}catch(F){w(F)}},_=k=>k.done?C(k.value):Promise.resolve(k.value).then(V,$);_((p=p.apply(m,a)).next())});class m{constructor(e){y(this,"target");y(this,"targetOrigin");y(this,"listeners");y(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 a(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function p(){return typeof window!="undefined"}const P=class{constructor(){p()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=a(),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.5.2-beta.5");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),P.messagingService=new m({target:r.contentWindow,targetOrigin:e}),P.isCommunicationReady=new Promise(i=>{var c;const s=d=>{var n;d.data.type==="headlessSDK:init"&&(i(),(n=P.messagingService)==null||n.removeListener(s))};(c=P.messagingService)==null||c.onReceive(s)})}request(r){return E(this,arguments,function*({api:e,payload:t}){return yield P.isCommunicationReady,new Promise((i,s)=>{var d,n;(d=P.messagingService)==null||d.send({type:e,data:t});const c=u=>{var h;const{type:o,data:l}=u.data;o===e&&(l.status==="resolved"?i(l.payload):s(l.payload),(h=P.messagingService)==null||h.removeListener(c))};(n=P.messagingService)==null||n.onReceive(c)})})}postMessage(e){var t;(t=P.messagingService)==null||t.send({type:e})}};let C=P;y(C,"messagingService",null),y(C,"isCommunicationReady");function w(f,e){if(f)throw new Error(e)}const V=new Set(["payment","payout"]),$=new Set(["en","fr","ar"]);class _{constructor(e){y(this,"options");y(this,"messagingService",null);y(this,"iframe",null);y(this,"isCommunicationReady",null);w(!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}){var d,n;(d=this.messagingService)==null||d.abortService();const r=a(),i=new URL(`${r}/embed/${this.options.type}/${t}`);i.searchParams.set("sdk","true"),i.searchParams.set("parent",window.location.origin),i.searchParams.set("version","js@1.5.2-beta.5");const s=(n=this.options.locale)==null?void 0:n.split("-")[0];s&&i.searchParams.set("lang",s),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 c=document.querySelector(e);return w(!c,`Couldn't find an element with selector ${e}!`),c.replaceChildren(this.iframe),this.messagingService=new m({target:this.iframe.contentWindow,targetOrigin:r}),this.isCommunicationReady=new Promise(u=>{var l;const o=h=>{var g;h.data.type==="sdk:init"&&(u(),(g=this.messagingService)==null||g.removeListener(o))};(l=this.messagingService)==null||l.onReceive(o)}),this.messagingService.onReceive((u,o)=>{var g,v,I,N;const{type:l,data:h}=u.data;switch(l){case"sdk:init":{o({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(v=(g=this.options).onComplete)==null||v.call(g,L({type:this.options.type},h)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(N=(I=this.options).onFail)==null||N.call(I,L({type:this.options.type},h)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return E(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 E(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class k{constructor(){y(this,"promise");y(this,"resolve");y(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 M(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function J(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function fe(f){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!f.includes(t))return t;return null}function ye(f){return(Array.isArray(f)?f.length:Object.keys(f).length)===0}function ve(f,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=f,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function we(f){return new Promise(e=>{setTimeout(()=>{e("done")},f*1e3)})}function K(f,e){f&&console.warn(e)}const G=new Set(["method","customerBalance","savedCard"]);class be{constructor(e){R(this,q);R(this,j);R(this,D);R(this,H);R(this,W);R(this,x);R(this,B);R(this,O);y(this,"options");y(this,"sdkApiHandler",new C);y(this,"sdkEmbed");y(this,"vaultSubmitListener",{current:null});y(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new _(de(L({},e),{headless:!0})),A(this,x,ue).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}})}proceedWith({intentId:e,type:t,id:r,metaData:i}){return w(!G.has(t),`type must be a valid one (${[...G].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,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 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 E(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:i,onCancel:s=()=>{},onError:c,onComplete:d,billingData:n={}}){if(yield ve("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const o=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:l,intent:h}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(l==="INTENT_FORM"){if(ye(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(g){throw yield this.resetSelectedMethod(e),g}o.onvalidatemerchant=g=>{fetch(`${J()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:h.secret,validation_url:g.validationURL})}).then(v=>v.ok?v.json():Promise.reject()).then(v=>o.completeMerchantValidation(v)).catch(c)},o.onpaymentauthorized=g=>{fetch(`${J()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:g.payment.token},secret:h.secret})}).then(v=>v.ok?v.json():Promise.reject()).then(()=>{o.completePayment(ApplePaySession.STATUS_SUCCESS),d()}).catch(()=>{o.completePayment(ApplePaySession.STATUS_FAILURE),c()})},o.oncancel=s,o.begin()})}renderForm({selector:e,intentId:t}){return w(!e,"selector is required for renderForm"),w(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){K(!!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 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(r=>{w(!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 i=[],s={},c=new Map;let d=!1;return A(this,W,me).call(this,i),{create:({elementType:n,elementOptions:u})=>{var N,Q;const o=new Map;let l=null,h;const g=L(L({},t),u.classes),v=((N=g==null?void 0:g.focus)==null?void 0:N.split(" "))||["MoneyHashElement--focus"],I=((Q=g==null?void 0:g.error)==null?void 0:Q.split(" "))||["MoneyHashElement--error"];return{mount:()=>{h=document.querySelector(u.selector),w(!h,`Couldn't find an element with selector ${u.selector}!`),h.classList.add("MoneyHashElement"),i.push(b=>{var X,Z,ee,te,ie,ne,se,re,ae;const{type:S,data:U}=b.data;if(S===`${n}@mount`&&(s[n]=U.isValid,(X=o.get(`${n}@mount`))==null||X()),S===`${n}@focus`){h.classList.add(...v),(Z=o.get(`${n}@focus`))==null||Z();return}if(S===`${n}@blur`){h.classList.remove(...v),(ee=o.get(`${n}@blur`))==null||ee();return}if(S===`${n}@error`){U.isValid?h.classList.remove(...I):h.classList.add(...I),(te=o.get(`${n}@error`))==null||te(U);return}if(S===`${n}@changeInput`){if((ie=o.get(`${n}@changeInput`))==null||ie({isValid:U.isValid,length:U.length}),s[n]=U.isValid,c.get("validityChange")){const T=Object.values(s).every(Boolean);T!==d&&((ne=c.get("validityChange"))==null||ne(T),d=T)}return}if(S===`${n}@cardNumberChange`){(se=o.get(`${n}@cardNumberChange`))==null||se(U);return}if(S===`${n}@key:Backspace`){(re=o.get(`${n}@key:Backspace`))==null||re();return}S===`${n}@key:Enter`&&((ae=o.get(`${n}@key:Enter`))==null||ae())}),l=A(this,B,pe).call(this,{container:h,elementType:n,elementOptions:u,styles:L(L({},e),u.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(b,S)=>{o.set(`${n}@${b}`,S)},off:b=>o.delete(`${n}@${b}`),focus:()=>{var b;(b=l==null?void 0:l.contentWindow)==null||b.postMessage({type:"focus"},M())},blur:()=>{var b;(b=l==null?void 0:l.contentWindow)==null||b.postMessage({type:"blur"},M())},clear:()=>{var b;(b=l==null?void 0:l.contentWindow)==null||b.postMessage({type:"clear"},M())}}},on:(n,u)=>{c.set(n,u)}}}submitForm(d){return E(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:i,saveCard:s,paymentMethod:c="CARD"}){const n=new k;let u,o;if(t){const h=fe(this.mountedCardElements);w(!!h,`You must mount ${h} element!`),this.vaultSubmitListener.current=g=>{const{type:v,data:I}=g.data;v==="vaultSubmit:success"&&n.resolve(I),v==="vaultSubmit:error"&&n.reject(I)},o=A(this,O,ge).call(this,{accessToken:t,saveCard:s}),u=yield n.promise}const l=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:c,lang:this.sdkEmbed.lang,billingData:r,shippingData:i,cardEmbed:u}});return o&&o.remove(),l})}submitCvv(r){return E(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 E(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:i}){switch(r){case"IFRAME":return A(this,q,ce).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,j,le).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return A(this,D,he).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return K(!0,`No expiration date provided!, make sure to check for it before usage | ||
(function(h,a){typeof exports=="object"&&typeof module!="undefined"?module.exports=a():typeof define=="function"&&define.amd?define(a):(h=typeof globalThis!="undefined"?globalThis:h||self,h.MoneyHash=a())})(this,function(){var q,ce,j,le,D,he,H,J,W,me,x,ue,B,pe,O,ge;"use strict";var Ee=Object.defineProperty,Pe=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var oe=Object.getOwnPropertySymbols;var Se=Object.prototype.hasOwnProperty,Le=Object.prototype.propertyIsEnumerable;var z=(h,a,p)=>a in h?Ee(h,a,{enumerable:!0,configurable:!0,writable:!0,value:p}):h[a]=p,S=(h,a)=>{for(var p in a||(a={}))Se.call(a,p)&&z(h,p,a[p]);if(oe)for(var p of oe(a))Le.call(a,p)&&z(h,p,a[p]);return h},de=(h,a)=>Pe(h,ke(a));var v=(h,a,p)=>(z(h,typeof a!="symbol"?a+"":a,p),p),Ae=(h,a,p)=>{if(!a.has(h))throw TypeError("Cannot "+p)};var A=(h,a,p)=>{if(a.has(h))throw TypeError("Cannot add the same private member more than once");a instanceof WeakSet?a.add(h):a.set(h,p)};var L=(h,a,p)=>(Ae(h,a,"access private method"),p);var E=(h,a,p)=>new Promise((C,b)=>{var V=k=>{try{_(p.next(k))}catch(F){b(F)}},$=k=>{try{_(p.throw(k))}catch(F){b(F)}},_=k=>k.done?C(k.value):Promise.resolve(k.value).then(V,$);_((p=p.apply(h,a)).next())});class h{constructor(e){v(this,"target");v(this,"targetOrigin");v(this,"listeners");v(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 a(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function p(){return typeof window!="undefined"}const P=class{constructor(){p()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=a(),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.5.2");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),P.messagingService=new h({target:r.contentWindow,targetOrigin:e}),P.isCommunicationReady=new Promise(i=>{var c;const s=d=>{var n;d.data.type==="headlessSDK:init"&&(i(),(n=P.messagingService)==null||n.removeListener(s))};(c=P.messagingService)==null||c.onReceive(s)})}request(r){return E(this,arguments,function*({api:e,payload:t}){return yield P.isCommunicationReady,new Promise((i,s)=>{var d,n;(d=P.messagingService)==null||d.send({type:e,data:t});const c=m=>{var u;const{type:o,data:l}=m.data;o===e&&(l.status==="resolved"?i(l.payload):s(l.payload),(u=P.messagingService)==null||u.removeListener(c))};(n=P.messagingService)==null||n.onReceive(c)})})}postMessage(e){var t;(t=P.messagingService)==null||t.send({type:e})}};let C=P;v(C,"messagingService",null),v(C,"isCommunicationReady");function b(g,e){if(g)throw new Error(e)}const V=new Set(["payment","payout"]),$=new Set(["en","fr","ar"]);class _{constructor(e){v(this,"options");v(this,"messagingService",null);v(this,"iframe",null);v(this,"isCommunicationReady",null);b(!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}){var d,n;(d=this.messagingService)==null||d.abortService();const r=a(),i=new URL(`${r}/embed/${this.options.type}/${t}`);i.searchParams.set("sdk","true"),i.searchParams.set("parent",window.location.origin),i.searchParams.set("version","js@1.5.2");const s=(n=this.options.locale)==null?void 0:n.split("-")[0];s&&i.searchParams.set("lang",s),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 c=document.querySelector(e);return b(!c,`Couldn't find an element with selector ${e}!`),c.replaceChildren(this.iframe),this.messagingService=new h({target:this.iframe.contentWindow,targetOrigin:r}),this.isCommunicationReady=new Promise(m=>{var l;const o=u=>{var y;u.data.type==="sdk:init"&&(m(),(y=this.messagingService)==null||y.removeListener(o))};(l=this.messagingService)==null||l.onReceive(o)}),this.messagingService.onReceive((m,o)=>{var y,w,R,N;const{type:l,data:u}=m.data;switch(l){case"sdk:init":{o({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(w=(y=this.options).onComplete)==null||w.call(y,S({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(N=(R=this.options).onFail)==null||N.call(R,S({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return E(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 E(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class k{constructor(){v(this,"promise");v(this,"resolve");v(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 M(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function K(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function fe(g){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!g.includes(t))return t;return null}function ye(g){return(Array.isArray(g)?g.length:Object.keys(g).length)===0}function ve(g,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=g,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function we(g){return new Promise(e=>{setTimeout(()=>{e("done")},g*1e3)})}function G(g,e){g&&console.warn(e)}const Q=new Set(["method","customerBalance","savedCard"]);class be{constructor(e){A(this,q);A(this,j);A(this,D);A(this,H);A(this,W);A(this,x);A(this,B);A(this,O);v(this,"options");v(this,"sdkApiHandler",new C);v(this,"sdkEmbed");v(this,"vaultSubmitListener",{current:null});v(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new _(de(S({},e),{headless:!0})),L(this,x,ue).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}})}proceedWith({intentId:e,type:t,id:r,metaData:i}){return b(!Q.has(t),`type must be a valid one (${[...Q].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,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 b(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(m){return E(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:i,onCancel:s=()=>{},onError:c,onComplete:d,billingData:n={}}){if(yield ve("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const o=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:l,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(l==="INTENT_FORM"){if(ye(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(y){throw yield this.resetSelectedMethod(e),y}o.onvalidatemerchant=y=>{fetch(`${K()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:y.validationURL})}).then(w=>w.ok?w.json():Promise.reject()).then(w=>o.completeMerchantValidation(w)).catch(c)},o.onpaymentauthorized=y=>{fetch(`${K()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:y.payment.token},secret:u.secret})}).then(w=>w.ok?w.json():Promise.reject()).then(()=>{o.completePayment(ApplePaySession.STATUS_SUCCESS),d()}).catch(()=>{o.completePayment(ApplePaySession.STATUS_FAILURE),c()})},o.oncancel=s,o.begin()})}renderForm({selector:e,intentId:t}){return b(!e,"selector is required for renderForm"),b(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){G(!!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 b(!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=>{b(!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 i=[],s={},c=new Map;let d=!1;return L(this,W,me).call(this,i),{create:({elementType:n,elementOptions:m})=>{var R,N;const o=new Map;let l=null;const u=S(S({},t),m.classes),y=((R=u==null?void 0:u.focus)==null?void 0:R.split(" "))||["MoneyHashElement--focus"],w=((N=u==null?void 0:u.error)==null?void 0:N.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const f=document.querySelector(m.selector);b(!f,`Couldn't find an element with selector ${m.selector}!`),f.classList.add("MoneyHashElement"),i.push(T=>{var X,Z,ee,te,ie,ne,se,re,ae;const{type:I,data:U}=T.data;if(I===`${n}@mount`&&(s[n]=U.isValid,(X=o.get(`${n}@mount`))==null||X()),I===`${n}@focus`){f.classList.add(...y),(Z=o.get(`${n}@focus`))==null||Z();return}if(I===`${n}@blur`){f.classList.remove(...y),(ee=o.get(`${n}@blur`))==null||ee();return}if(I===`${n}@error`){U.isValid?f.classList.remove(...w):f.classList.add(...w),(te=o.get(`${n}@error`))==null||te(U);return}if(I===`${n}@changeInput`){if((ie=o.get(`${n}@changeInput`))==null||ie({isValid:U.isValid,length:U.length}),s[n]=U.isValid,c.get("validityChange")){const Y=Object.values(s).every(Boolean);Y!==d&&((ne=c.get("validityChange"))==null||ne(Y),d=Y)}return}if(I===`${n}@cardNumberChange`){(se=o.get(`${n}@cardNumberChange`))==null||se(U);return}if(I===`${n}@key:Backspace`){(re=o.get(`${n}@key:Backspace`))==null||re();return}I===`${n}@key:Enter`&&((ae=o.get(`${n}@key:Enter`))==null||ae())}),l=L(this,B,pe).call(this,{container:f,elementType:n,elementOptions:m,styles:S(S({},e),m.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(f,T)=>{o.set(`${n}@${f}`,T)},off:f=>o.delete(`${n}@${f}`),focus:()=>{var f;(f=l==null?void 0:l.contentWindow)==null||f.postMessage({type:"focus"},M())},blur:()=>{var f;(f=l==null?void 0:l.contentWindow)==null||f.postMessage({type:"blur"},M())},clear:()=>{var f;(f=l==null?void 0:l.contentWindow)==null||f.postMessage({type:"clear"},M())}}},on:(n,m)=>{c.set(n,m)}}}submitForm(d){return E(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:i,saveCard:s,paymentMethod:c="CARD"}){const n=new k;let m,o;if(t){const u=fe(this.mountedCardElements);b(!!u,`You must mount ${u} element!`),this.vaultSubmitListener.current=y=>{const{type:w,data:R}=y.data;w==="vaultSubmit:success"&&n.resolve(R),w==="vaultSubmit:error"&&n.reject(R)},o=L(this,O,ge).call(this,{accessToken:t,saveCard:s}),m=yield n.promise}const l=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:c,lang:this.sdkEmbed.lang,billingData:r,shippingData:i,cardEmbed:m}});return o&&o.remove(),l})}submitCvv(r){return E(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 E(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:i}){switch(r){case"IFRAME":return L(this,q,ce).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return L(this,j,le).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return L(this,D,he).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){if(!e)return G(!0,`No expiration date provided!, make sure to check for it before usage | ||
@@ -7,2 +7,2 @@ if (intentDetails.intent.expirationDate) { | ||
}) | ||
}`),()=>{};const r=new Date(e),i=setInterval(()=>E(this,null,function*(){const s=new Date;r<s&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}return q=new WeakSet,ce=function(r){return E(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");w(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=t,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),i==null||i.replaceChildren(s),yield A(this,H,z).call(this,{intentId:e}),s.remove()})},j=new WeakSet,le=function(i){return E(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:c=400,left:d=200,top:n=200}=r.window||{},u=window.open(t,"",`width=${s},height=${c},left=${d},top=${n}`);w(!u,"Popup blocked by browser!"),yield A(this,H,z).call(this,{intentId:e,isUsingPopUp:!0}),u==null||u.close()})},D=new WeakSet,he=function(r){return E(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},H=new WeakSet,z=function(r){return E(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new k,s=c=>E(this,null,function*(){var n,u,o,l;if(c.origin!==a())return;const{type:d}=c.data;if(d==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[h]=yield Promise.all([this.getIntentDetails(e),we(2)]),g=h.transaction.status.split(".")[1];g==="successful"||g.startsWith("pending")?(u=(n=this.options).onComplete)==null||u.call(n,L({type:this.options.type},h)):(l=(o=this.options).onFail)==null||l.call(o,L({type:this.options.type},h)),i.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),i.promise})},W=new WeakSet,me=function(e){const t=r=>{r.origin===M()&&e.forEach(i=>{i(r)})};window.addEventListener("message",t)},x=new WeakSet,ue=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},B=new WeakSet,pe=function({container:e,elementType:t,elementOptions:r,styles:i,fontSourceCss:s}){var u,o,l,h;const c=M(),d=new URL(`${c}/vaultField/vaultField.html`);s&&d.searchParams.set("fontSourceCss",s),d.searchParams.set("host",btoa(window.location.origin)),d.searchParams.set("type",t),((u=r.validation)==null?void 0:u.required)!==void 0&&d.searchParams.set("required",`${(o=r.validation)==null?void 0:o.required}`),d.searchParams.set("placeholder",(l=r.placeholder)!=null?l:""),d.searchParams.set("lang",this.sdkEmbed.lang),d.searchParams.set("direction",(i==null?void 0:i.direction)||""),d.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),d.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),d.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),d.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),d.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),d.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),d.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),d.searchParams.set("padding",(i==null?void 0:i.padding)||"");const n=document.createElement("iframe");return n.src=d.toString(),n.style.height=(h=i==null?void 0:i.height)!=null?h:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n),n},O=new WeakSet,ge=function({accessToken:e,saveCard:t}){const r=M(),i=F(),s=new URL(`${r}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang),t!==void 0&&s.searchParams.set("save_card",`${t}`);const c=document.createElement("iframe");return c.id="moneyhash-submit-iframe",c.src=s.toString(),c.hidden=!0,document.body.appendChild(c),c},be}); | ||
}`),()=>{};const r=new Date(e),i=setInterval(()=>E(this,null,function*(){const s=new Date;r<s&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}return q=new WeakSet,ce=function(r){return E(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");b(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=t,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),i==null||i.replaceChildren(s),yield L(this,H,J).call(this,{intentId:e}),s.remove()})},j=new WeakSet,le=function(i){return E(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:c=400,left:d=200,top:n=200}=r.window||{},m=window.open(t,"",`width=${s},height=${c},left=${d},top=${n}`);b(!m,"Popup blocked by browser!"),yield L(this,H,J).call(this,{intentId:e,isUsingPopUp:!0}),m==null||m.close()})},D=new WeakSet,he=function(r){return E(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},H=new WeakSet,J=function(r){return E(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new k,s=c=>E(this,null,function*(){var n,m,o,l;if(c.origin!==a())return;const{type:d}=c.data;if(d==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),we(2)]),y=u.transaction.status.split(".")[1];y==="successful"||y.startsWith("pending")?(m=(n=this.options).onComplete)==null||m.call(n,S({type:this.options.type},u)):(l=(o=this.options).onFail)==null||l.call(o,S({type:this.options.type},u)),i.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),i.promise})},W=new WeakSet,me=function(e){const t=r=>{r.origin===M()&&e.forEach(i=>{i(r)})};window.addEventListener("message",t)},x=new WeakSet,ue=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},B=new WeakSet,pe=function({container:e,elementType:t,elementOptions:r,styles:i,fontSourceCss:s}){var m,o,l,u;const c=M(),d=new URL(`${c}/vaultField/vaultField.html`);s&&d.searchParams.set("fontSourceCss",s),d.searchParams.set("host",btoa(window.location.origin)),d.searchParams.set("type",t),((m=r.validation)==null?void 0:m.required)!==void 0&&d.searchParams.set("required",`${(o=r.validation)==null?void 0:o.required}`),d.searchParams.set("placeholder",(l=r.placeholder)!=null?l:""),d.searchParams.set("lang",this.sdkEmbed.lang),d.searchParams.set("direction",(i==null?void 0:i.direction)||""),d.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),d.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),d.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),d.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),d.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),d.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),d.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),d.searchParams.set("padding",(i==null?void 0:i.padding)||"");const n=document.createElement("iframe");return n.src=d.toString(),n.style.height=(u=i==null?void 0:i.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},O=new WeakSet,ge=function({accessToken:e,saveCard:t}){const r=M(),i=F(),s=new URL(`${r}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang),t!==void 0&&s.searchParams.set("save_card",`${t}`);const c=document.createElement("iframe");return c.id="moneyhash-submit-iframe",c.src=s.toString(),c.hidden=!0,document.body.appendChild(c),c},be}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var n=Object.defineProperty;var d=(t,e,s)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var a=(t,e,s)=>(d(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-30544ab3.cjs");class o{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start({selector:e,intentId:s}){return r.throwIf(!e,"selector is required for start"),r.throwIf(!s,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:s})}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 n=Object.defineProperty;var d=(t,e,s)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var a=(t,e,s)=>(d(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-24962673.cjs");class o{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start({selector:e,intentId:s}){return r.throwIf(!e,"selector is required for start"),r.throwIf(!s,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:s})}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o; |
var o = Object.defineProperty; | ||
var n = (r, s, e) => s in r ? o(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e; | ||
var t = (r, s, e) => (n(r, typeof s != "symbol" ? s + "" : s, e), e); | ||
import { S as i, t as d, w as u, s as a } from "./warnIf-6b9dc7c7.js"; | ||
import { S as i, t as d, w as u, s as a } from "./warnIf-d62a2abd.js"; | ||
class b { | ||
@@ -6,0 +6,0 @@ constructor(s) { |
@@ -1,1 +0,1 @@ | ||
(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,s,t)=>s in i?F(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,w=(i,s)=>{for(var t in s||(s={}))U.call(s,t)&&v(i,t,s[t]);if(O)for(var t of O(s))$.call(s,t)&&v(i,t,s[t]);return i};var a=(i,s,t)=>(v(i,typeof s!="symbol"?s+"":s,t),t);var b=(i,s,t)=>new Promise((g,o)=>{var p=r=>{try{h(t.next(r))}catch(e){o(e)}},f=r=>{try{h(t.throw(r))}catch(e){o(e)}},h=r=>r.done?g(r.value):Promise.resolve(r.value).then(p,f);h((t=t.apply(i,s)).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(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 s(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function t(r,e){if(r)throw new Error(e)}const g=new Set(["payment","payout"]),o=new Set(["en","fr","ar"]);class p{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!g.has(e.type),`MoneyHash constructor must be called with valid type (${[...g].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}){var L,M;(L=this.messagingService)==null||L.abortService();const S=s(),c=new URL(`${S}/embed/${this.options.type}/${n}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.5.2-beta.5");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),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 E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const m=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(m))};(l=this.messagingService)==null||l.onReceive(m)}),this.messagingService.onReceive((y,m)=>{var d,I,k,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(I=(d=this.options).onComplete)==null||I.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(k=this.options).onFail)==null||C.call(k,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(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 b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function f(r,e){r&&console.warn(e)}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new p(e)}start({selector:e,intentId:n}){return t(!e,"selector is required for start"),t(!n,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:n})}setLocale(e){f(!!e&&!o.has(e),`Invalid locale. Supported languages (${[...o].join(" | ")})`);const n=o.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}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 F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,s,t)=>s in i?F(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,w=(i,s)=>{for(var t in s||(s={}))U.call(s,t)&&v(i,t,s[t]);if(O)for(var t of O(s))$.call(s,t)&&v(i,t,s[t]);return i};var a=(i,s,t)=>(v(i,typeof s!="symbol"?s+"":s,t),t);var b=(i,s,t)=>new Promise((g,o)=>{var p=r=>{try{h(t.next(r))}catch(e){o(e)}},f=r=>{try{h(t.throw(r))}catch(e){o(e)}},h=r=>r.done?g(r.value):Promise.resolve(r.value).then(p,f);h((t=t.apply(i,s)).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(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 s(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function t(r,e){if(r)throw new Error(e)}const g=new Set(["payment","payout"]),o=new Set(["en","fr","ar"]);class p{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!g.has(e.type),`MoneyHash constructor must be called with valid type (${[...g].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}){var L,M;(L=this.messagingService)==null||L.abortService();const S=s(),c=new URL(`${S}/embed/${this.options.type}/${n}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.5.2");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),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 E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const m=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(m))};(l=this.messagingService)==null||l.onReceive(m)}),this.messagingService.onReceive((y,m)=>{var d,I,k,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(I=(d=this.options).onComplete)==null||I.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(k=this.options).onFail)==null||C.call(k,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(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 b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function f(r,e){r&&console.warn(e)}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new p(e)}start({selector:e,intentId:n}){return t(!e,"selector is required for start"),t(!n,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:n})}setLocale(e){f(!!e&&!o.has(e),`Invalid locale. Supported languages (${[...o].join(" | ")})`);const n=o.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h}); |
{ | ||
"name": "@moneyhash/js-sdk", | ||
"version": "1.5.2-beta.5", | ||
"version": "1.5.2", | ||
"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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2581
2
380554