@moneyhash/js-sdk
Advanced tools
Comparing version 1.5.2-beta.0 to 1.5.2-beta.1
@@ -1,2 +0,2 @@ | ||
"use strict";var se=Object.defineProperty,oe=Object.defineProperties;var de=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var ce=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var q=(s,e,t)=>e in s?se(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,k=(s,e)=>{for(var t in e||(e={}))ce.call(e,t)&&q(s,t,e[t]);if(J)for(var t of J(e))le.call(e,t)&&q(s,t,e[t]);return s},K=(s,e)=>oe(s,de(e));var v=(s,e,t)=>(q(s,typeof e!="symbol"?e+"":e,t),t),ue=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var b=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)};var P=(s,e,t)=>(ue(s,e,"access private method"),t);var w=(s,e,t)=>new Promise((o,r)=>{var a=n=>{try{i(t.next(n))}catch(l){r(l)}},c=n=>{try{i(t.throw(n))}catch(l){r(l)}},i=n=>n.done?o(n.value):Promise.resolve(n.value).then(a,c);i((t=t.apply(s,e)).next())});const h=require("./warnIf-fba58e46.cjs");function pe(){return typeof window!="undefined"}const y=class{constructor(){pe()&&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.5.2-beta.0");const o=document.createElement("iframe");o.id="moneyhash-headless-sdk",o.src=t.toString(),o.hidden=!0,document.body.appendChild(o),y.messagingService=new h.MessagingService({target:o.contentWindow,targetOrigin:e}),y.isCommunicationReady=new Promise(r=>{var c;const a=i=>{var n;i.data.type==="headlessSDK:init"&&(r(),(n=y.messagingService)==null||n.removeListener(a))};(c=y.messagingService)==null||c.onReceive(a)})}request(o){return w(this,arguments,function*({api:e,payload:t}){return yield y.isCommunicationReady,new Promise((r,a)=>{var i,n;(i=y.messagingService)==null||i.send({type:e,data:t});const c=l=>{var p;const{type:d,data:u}=l.data;d===e&&(u.status==="resolved"?r(u.payload):a(u.payload),(p=y.messagingService)==null||p.removeListener(c))};(n=y.messagingService)==null||n.onReceive(c)})})}postMessage(e){var t;(t=y.messagingService)==null||t.send({type:e})}};let L=y;v(L,"messagingService",null),v(L,"isCommunicationReady");class G{constructor(){v(this,"promise");v(this,"resolve");v(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function he(){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 Q(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function me(s){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!s.includes(t))return t;return null}function ge(s){return(Array.isArray(s)?s.length:Object.keys(s).length)===0}function fe(s,e){return new Promise((t,o)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=s,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{o(new Error("Script failed to load"))}),document.body.appendChild(a)})}function we(s){return new Promise(e=>{setTimeout(()=>{e("done")},s*1e3)})}const X=new Set(["method","customerBalance","savedCard"]);var C,Z,U,ee,R,te,A,N,M,re,$,ne,_,ae,F,ie;class ve{constructor(e){b(this,C);b(this,U);b(this,R);b(this,A);b(this,M);b(this,$);b(this,_);b(this,F);v(this,"options");v(this,"sdkApiHandler",new L);v(this,"sdkEmbed");v(this,"vaultSubmitListener",{current:null});v(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new h.SDKEmbed(K(k({},e),{headless:!0})),P(this,$,ne).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:o,metaData:r}){return h.throwIf(!X.has(t),`type must be a valid one (${[...X].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:o,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 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 w(this,arguments,function*({intentId:e,currency:t,amount:o,countryCode:r,onCancel:a=()=>{},onError:c,onComplete:i,billingData:n={}}){if(yield fe("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:`${o}`}}),{state:u,intent:p}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(u==="INTENT_FORM"){if(ge(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(`${Q()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:p.secret,validation_url:m.validationURL})}).then(f=>f.ok?f.json():Promise.reject()).then(f=>d.completeMerchantValidation(f)).catch(c)},d.onpaymentauthorized=m=>{fetch(`${Q()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:m.payment.token,secret:p.secret})}).then(f=>f.ok?f.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),i()}).catch(()=>{d.completePayment(ApplePaySession.STATUS_FAILURE),c()})},d.oncancel=a,d.begin()})}renderForm({selector:e,intentId:t}){return h.throwIf(!e,"selector is required for renderForm"),h.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}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(o=>{h.throwIf(!o.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:o}){const r=[],a={},c=new Map;let i=!1;return P(this,M,re).call(this,r),{create:({elementType:n,elementOptions:l})=>{var D,W;const d=new Map;let u=null,p;const m=k(k({},t),l.classes),f=((D=m==null?void 0:m.focus)==null?void 0:D.split(" "))||["MoneyHashElement--focus"],H=((W=m==null?void 0:m.error)==null?void 0:W.split(" "))||["MoneyHashElement--error"];return{mount:()=>{p=document.querySelector(l.selector),h.throwIf(!p,`Couldn't find an element with selector ${l.selector}!`),p.classList.add("MoneyHashElement"),r.push(g=>{var j,x,T,B,Y,O,z;const{type:E,data:I}=g.data;if(E===`${n}@mount`&&(a[n]=I.isValid,(j=d.get(`${n}@mount`))==null||j()),E===`${n}@focus`){p.classList.add(...f),(x=d.get(`${n}@focus`))==null||x();return}if(E===`${n}@blur`){p.classList.remove(...f),(T=d.get(`${n}@blur`))==null||T();return}if(E===`${n}@error`){I.isValid?p.classList.remove(...H):p.classList.add(...H),(B=d.get(`${n}@error`))==null||B(I);return}if(E===`${n}@changeInput`){if((Y=d.get(`${n}@changeInput`))==null||Y({isValid:I.isValid,length:I.length}),a[n]=I.isValid,c.get("validityChange")){const V=Object.values(a).every(Boolean);V!==i&&((O=c.get("validityChange"))==null||O(V),i=V)}return}E===`${n}@cardNumberChange`&&((z=d.get(`${n}@cardNumberChange`))==null||z(I))}),u=P(this,_,ae).call(this,{container:p,elementType:n,elementOptions:l,styles:k(k({},e),l.styles),fontSourceCss:o}),this.mountedCardElements.push(n)},on:(g,E)=>{d.set(`${n}@${g}`,E)},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(c){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:o,shippingData:r,saveCard:a}){const i=me(this.mountedCardElements);h.throwIf(!!i,`You must mount ${i} element!`);const n=new G;let l,d;t&&(this.vaultSubmitListener.current=p=>{const{type:m,data:f}=p.data;m==="vaultSubmit:success"&&n.resolve(f),m==="vaultSubmit:error"&&n.reject(f)},d=P(this,F,ie).call(this,{accessToken:t,saveCard:a}),l=yield n.promise);const u=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:o,shippingData:r,cardEmbed:l}});return d&&d.remove(),u})}submitCvv(o){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:o,options:r}){switch(o){case"IFRAME":return P(this,C,Z).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return P(this,U,ee).call(this,{url:t,intentId:e,options:r});case"REDIRECT":return P(this,R,te).call(this,{url:t,options:r});default:return null}})}onExpiration(e,t){if(!e)return h.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 q=(s,e,t)=>e in s?de(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,k=(s,e)=>{for(var t in e||(e={}))ue.call(e,t)&&q(s,t,e[t]);if(G)for(var t of G(e))he.call(e,t)&&q(s,t,e[t]);return s},Q=(s,e)=>ce(s,le(e));var v=(s,e,t)=>(q(s,typeof e!="symbol"?e+"":e,t),t),pe=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var b=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)};var E=(s,e,t)=>(pe(s,e,"access private method"),t);var w=(s,e,t)=>new Promise((o,r)=>{var a=n=>{try{i(t.next(n))}catch(l){r(l)}},c=n=>{try{i(t.throw(n))}catch(l){r(l)}},i=n=>n.done?o(n.value):Promise.resolve(n.value).then(a,c);i((t=t.apply(s,e)).next())});const p=require("./warnIf-604ca43b.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.1");const o=document.createElement("iframe");o.id="moneyhash-headless-sdk",o.src=t.toString(),o.hidden=!0,document.body.appendChild(o),y.messagingService=new p.MessagingService({target:o.contentWindow,targetOrigin:e}),y.isCommunicationReady=new Promise(r=>{var c;const a=i=>{var n;i.data.type==="headlessSDK:init"&&(r(),(n=y.messagingService)==null||n.removeListener(a))};(c=y.messagingService)==null||c.onReceive(a)})}request(o){return w(this,arguments,function*({api:e,payload:t}){return yield y.isCommunicationReady,new Promise((r,a)=>{var i,n;(i=y.messagingService)==null||i.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 L=y;v(L,"messagingService",null),v(L,"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(s){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!s.includes(t))return t;return null}function we(s){return(Array.isArray(s)?s.length:Object.keys(s).length)===0}function ve(s,e){return new Promise((t,o)=>{if(document.getElementById(e)){t(void 0);return}const a=document.createElement("script");a.src=s,a.id=e,a.addEventListener("load",()=>{t(void 0)}),a.addEventListener("error",()=>{o(new Error("Script failed to load"))}),document.body.appendChild(a)})}function ye(s){return new Promise(e=>{setTimeout(()=>{e("done")},s*1e3)})}const ee=new Set(["method","customerBalance","savedCard"]);var C,te,U,re,R,ne,A,N,$,ae,M,ie,_,se,F,oe;class Pe{constructor(e){b(this,C);b(this,U);b(this,R);b(this,A);b(this,$);b(this,M);b(this,_);b(this,F);v(this,"options");v(this,"sdkApiHandler",new L);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,M,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:o,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:o,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:o,countryCode:r,onCancel:a=()=>{},onError:c,onComplete:i,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:`${o}`}}),{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:m.payment.token,secret:h.secret})}).then(f=>f.ok?f.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),i()}).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(o=>{p.throwIf(!o.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:o}){const r=[],a={},c=new Map;let i=!1;return E(this,$,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"],H=((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(...H):h.classList.add(...H),(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 V=Object.values(a).every(Boolean);V!==i&&((O=c.get("validityChange"))==null||O(V),i=V)}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,_,se).call(this,{container:h,elementType:n,elementOptions:l,styles:k(k({},e),l.styles),fontSourceCss:o}),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(c){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:o,shippingData:r,saveCard:a}){const i=fe(this.mountedCardElements);p.throwIf(!!i,`You must mount ${i} element!`);const n=new X;let l,d;t&&(this.vaultSubmitListener.current=h=>{const{type:m,data:f}=h.data;m==="vaultSubmit:success"&&n.resolve(f),m==="vaultSubmit:error"&&n.reject(f)},d=E(this,F,oe).call(this,{accessToken:t,saveCard:a}),l=yield n.promise);const u=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:o,shippingData:r,cardEmbed:l}});return d&&d.remove(),u})}submitCvv(o){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:o,options:r}){switch(o){case"IFRAME":return E(this,C,te).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return E(this,U,re).call(this,{url:t,intentId:e,options:r});case"REDIRECT":return E(this,R,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 | ||
@@ -7,2 +7,2 @@ if (intentDetails.intent.expirationDate) { | ||
}) | ||
}`),()=>{};const o=new Date(e),r=setInterval(()=>w(this,null,function*(){const a=new Date;o<a&&(clearInterval(r),t())}),1e3);return()=>clearInterval(r)}}C=new WeakSet,Z=function(o){return w(this,arguments,function*({intentId:e,url:t}){const r=document.querySelector("#rendered-url-iframe-container");h.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,A,N).call(this,{intentId:e}),a.remove()})},U=new WeakSet,ee=function(r){return w(this,arguments,function*({intentId:e,url:t,options:o={}}){const{width:a=600,height:c=400,left:i=200,top:n=200}=o.window||{},l=window.open(t,"",`width=${a},height=${c},left=${i},top=${n}`);h.throwIf(!l,"Popup blocked by browser!"),yield P(this,A,N).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},R=new WeakSet,te=function(o){return w(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},A=new WeakSet,N=function(o){return w(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const r=new G,a=c=>w(this,null,function*(){var n,l,d,u;if(c.origin!==h.getIframeUrl())return;const{type:i}=c.data;if(i==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[p]=yield Promise.all([this.getIntentDetails(e),we(2)]),m=p.transaction.status.split(".")[1];m==="successful"||m.startsWith("pending")?(l=(n=this.options).onComplete)==null||l.call(n,k({type:this.options.type},p)):(u=(d=this.options).onFail)==null||u.call(d,k({type:this.options.type},p)),r.resolve(()=>null),window.removeEventListener("message",a)}});return window.addEventListener("message",a),r.promise})},M=new WeakSet,re=function(e){const t=o=>{o.origin===S()&&e.forEach(r=>{r(o)})};window.addEventListener("message",t)},$=new WeakSet,ne=function(e){const t=o=>{e.current&&e.current(o)};window.addEventListener("message",t)},_=new WeakSet,ae=function({container:e,elementType:t,elementOptions:o,styles:r,fontSourceCss:a}){var l,d,u,p;const c=S(),i=new URL(`${c}/vaultField/vaultField.html`);a&&i.searchParams.set("fontSourceCss",a),i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((l=o.validation)==null?void 0:l.required)!==void 0&&i.searchParams.set("required",`${(d=o.validation)==null?void 0:d.required}`),i.searchParams.set("placeholder",(u=o.placeholder)!=null?u:""),i.searchParams.set("lang",this.sdkEmbed.lang),i.searchParams.set("direction",(r==null?void 0:r.direction)||""),i.searchParams.set("color",JSON.stringify(r!=null&&r.color?r.color:"#000")),i.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),i.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),i.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),i.searchParams.set("fontFamily",(r==null?void 0:r.fontFamily)||""),i.searchParams.set("fontWeight",`${r==null?void 0:r.fontWeight}`),i.searchParams.set("fontStyle",(r==null?void 0:r.fontStyle)||""),i.searchParams.set("padding",(r==null?void 0:r.padding)||"");const n=document.createElement("iframe");return n.src=i.toString(),n.style.height=(p=r==null?void 0:r.height)!=null?p:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n),n},F=new WeakSet,ie=function({accessToken:e,saveCard:t}){const o=S(),r=he(),a=new URL(`${o}/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=ve; | ||
}`),()=>{};const o=new Date(e),r=setInterval(()=>w(this,null,function*(){const a=new Date;o<a&&(clearInterval(r),t())}),1e3);return()=>clearInterval(r)}}C=new WeakSet,te=function(o){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,A,N).call(this,{intentId:e}),a.remove()})},U=new WeakSet,re=function(r){return w(this,arguments,function*({intentId:e,url:t,options:o={}}){const{width:a=600,height:c=400,left:i=200,top:n=200}=o.window||{},l=window.open(t,"",`width=${a},height=${c},left=${i},top=${n}`);p.throwIf(!l,"Popup blocked by browser!"),yield E(this,A,N).call(this,{intentId:e,isUsingPopUp:!0}),l==null||l.close()})},R=new WeakSet,ne=function(o){return w(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},A=new WeakSet,N=function(o){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:i}=c.data;if(i==="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})},$=new WeakSet,ae=function(e){const t=o=>{o.origin===S()&&e.forEach(r=>{r(o)})};window.addEventListener("message",t)},M=new WeakSet,ie=function(e){const t=o=>{e.current&&e.current(o)};window.addEventListener("message",t)},_=new WeakSet,se=function({container:e,elementType:t,elementOptions:o,styles:r,fontSourceCss:a}){var l,d,u,h;const c=S(),i=new URL(`${c}/vaultField/vaultField.html`);a&&i.searchParams.set("fontSourceCss",a),i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((l=o.validation)==null?void 0:l.required)!==void 0&&i.searchParams.set("required",`${(d=o.validation)==null?void 0:d.required}`),i.searchParams.set("placeholder",(u=o.placeholder)!=null?u:""),i.searchParams.set("lang",this.sdkEmbed.lang),i.searchParams.set("direction",(r==null?void 0:r.direction)||""),i.searchParams.set("color",JSON.stringify(r!=null&&r.color?r.color:"#000")),i.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),i.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),i.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),i.searchParams.set("fontFamily",(r==null?void 0:r.fontFamily)||""),i.searchParams.set("fontWeight",`${r==null?void 0:r.fontWeight}`),i.searchParams.set("fontStyle",(r==null?void 0:r.fontStyle)||""),i.searchParams.set("padding",(r==null?void 0:r.padding)||"");const n=document.createElement("iframe");return n.src=i.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},F=new WeakSet,oe=function({accessToken:e,saveCard:t}){const o=S(),r=ge(),a=new URL(`${o}/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; |
@@ -106,3 +106,3 @@ export declare interface AbstractIntent { | ||
}) => void): void; | ||
on<T extends Extract<ElementEvents, "mount" | "focus" | "blur">>(event: T, callback: () => void): void; | ||
on<T extends ElementEvents>(event: T, callback: () => void): void; | ||
off: (event: ElementEvents) => boolean; | ||
@@ -117,3 +117,3 @@ focus: () => void; | ||
export declare type ElementEvents = "mount" | "focus" | "blur" | "error" | "changeInput" | "cardNumberChange"; | ||
export declare type ElementEvents = "mount" | "focus" | "blur" | "error" | "changeInput" | "cardNumberChange" | "key:Backspace" | "key:Enter"; | ||
@@ -120,0 +120,0 @@ export declare type ElementProps = { |
@@ -1,14 +0,14 @@ | ||
var ce = Object.defineProperty, le = Object.defineProperties; | ||
var ue = Object.getOwnPropertyDescriptors; | ||
var K = Object.getOwnPropertySymbols; | ||
var pe = Object.prototype.hasOwnProperty, me = Object.prototype.propertyIsEnumerable; | ||
var N = (s, e, t) => e in s ? ce(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, k = (s, e) => { | ||
var ue = Object.defineProperty, pe = Object.defineProperties; | ||
var he = Object.getOwnPropertyDescriptors; | ||
var Q = Object.getOwnPropertySymbols; | ||
var me = Object.prototype.hasOwnProperty, ge = Object.prototype.propertyIsEnumerable; | ||
var N = (s, e, t) => e in s ? ue(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, k = (s, e) => { | ||
for (var t in e || (e = {})) | ||
pe.call(e, t) && N(s, t, e[t]); | ||
if (K) | ||
for (var t of K(e)) | ||
me.call(e, t) && N(s, t, e[t]); | ||
me.call(e, t) && N(s, t, e[t]); | ||
if (Q) | ||
for (var t of Q(e)) | ||
ge.call(e, t) && N(s, t, e[t]); | ||
return s; | ||
}, G = (s, e) => le(s, ue(e)); | ||
var v = (s, e, t) => (N(s, typeof e != "symbol" ? e + "" : e, t), t), he = (s, e, t) => { | ||
}, X = (s, e) => pe(s, he(e)); | ||
var v = (s, e, t) => (N(s, typeof e != "symbol" ? e + "" : e, t), t), fe = (s, e, t) => { | ||
if (!e.has(s)) | ||
@@ -22,3 +22,3 @@ throw TypeError("Cannot " + t); | ||
}; | ||
var y = (s, e, t) => (he(s, e, "access private method"), t); | ||
var P = (s, e, t) => (fe(s, e, "access private method"), t); | ||
var f = (s, e, t) => new Promise((o, r) => { | ||
@@ -40,4 +40,4 @@ var n = (a) => { | ||
}); | ||
import { M as ge, g as te, S as fe, t as P, w as Q, s as q } from "./warnIf-daa85568.js"; | ||
function ve() { | ||
import { M as ve, g as ae, S as we, t as E, w as Z, s as q } from "./warnIf-f9a95079.js"; | ||
function ye() { | ||
return typeof window != "undefined"; | ||
@@ -47,3 +47,3 @@ } | ||
constructor() { | ||
ve() && this.initSDKCommunicationIframe(); | ||
ye() && this.initSDKCommunicationIframe(); | ||
} | ||
@@ -53,6 +53,6 @@ initSDKCommunicationIframe() { | ||
return; | ||
const e = te(), 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.0"); | ||
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.1"); | ||
const o = document.createElement("iframe"); | ||
o.id = "moneyhash-headless-sdk", o.src = t.toString(), o.hidden = !0, document.body.appendChild(o), w.messagingService = new ge({ | ||
o.id = "moneyhash-headless-sdk", o.src = t.toString(), o.hidden = !0, document.body.appendChild(o), w.messagingService = new ve({ | ||
target: o.contentWindow, | ||
@@ -96,3 +96,3 @@ targetOrigin: e | ||
v(L, "messagingService", null), v(L, "isCommunicationReady"); | ||
class X { | ||
class ee { | ||
constructor() { | ||
@@ -107,3 +107,3 @@ v(this, "promise"); | ||
} | ||
function we() { | ||
function Pe() { | ||
var e; | ||
@@ -116,7 +116,7 @@ return (e = window.MONEYHASH_VAULT_API_URL) != null ? e : "https://vault.moneyhash.io"; | ||
} | ||
function Z() { | ||
function te() { | ||
var e; | ||
return (e = window.API_URL) != null ? e : "https://web.moneyhash.io"; | ||
} | ||
function ye(s) { | ||
function Ee(s) { | ||
const e = [ | ||
@@ -133,6 +133,6 @@ "cardNumber", | ||
} | ||
function Pe(s) { | ||
function be(s) { | ||
return (Array.isArray(s) ? s.length : Object.keys(s).length) === 0; | ||
} | ||
function be(s, e) { | ||
function ke(s, e) { | ||
return new Promise((t, o) => { | ||
@@ -151,3 +151,3 @@ if (document.getElementById(e)) { | ||
} | ||
function Ee(s) { | ||
function Se(s) { | ||
return new Promise((e) => { | ||
@@ -159,3 +159,3 @@ setTimeout(() => { | ||
} | ||
const ee = /* @__PURE__ */ new Set([ | ||
const re = /* @__PURE__ */ new Set([ | ||
"method", | ||
@@ -165,4 +165,4 @@ "customerBalance", | ||
]); | ||
var C, re, U, ae, R, ne, I, H, M, ie, $, se, _, oe, F, de; | ||
class Le { | ||
var C, ne, U, ie, R, se, I, H, $, oe, M, de, _, ce, F, le; | ||
class Ce { | ||
constructor(e) { | ||
@@ -173,4 +173,4 @@ b(this, C); | ||
b(this, I); | ||
b(this, $); | ||
b(this, M); | ||
b(this, $); | ||
b(this, _); | ||
@@ -185,3 +185,3 @@ b(this, F); | ||
v(this, "mountedCardElements", []); | ||
this.options = e, this.sdkEmbed = new fe(G(k({}, e), { headless: !0 })), y(this, $, se).call(this, this.vaultSubmitListener); | ||
this.options = e, this.sdkEmbed = new we(X(k({}, e), { headless: !0 })), P(this, M, de).call(this, this.vaultSubmitListener); | ||
} | ||
@@ -280,5 +280,5 @@ /** | ||
}) { | ||
return P( | ||
!ee.has(t), | ||
`type must be a valid one (${[...ee].join( | ||
return E( | ||
!re.has(t), | ||
`type must be a valid one (${[...re].join( | ||
" | " | ||
@@ -340,3 +340,3 @@ )})` | ||
}) { | ||
return P( | ||
return E( | ||
this.options.type === "payout", | ||
@@ -403,3 +403,3 @@ "deleteCard is allowed only for payment intent!" | ||
}) { | ||
if (yield be( | ||
if (yield ke( | ||
"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js", | ||
@@ -426,3 +426,3 @@ "moneyHash-apple-pay-sdk" | ||
if (u === "INTENT_FORM") { | ||
if (Pe(a)) | ||
if (be(a)) | ||
throw new Error( | ||
@@ -441,7 +441,7 @@ "Billing data is missing while calling payWithApplePay" | ||
} | ||
} catch (m) { | ||
throw yield this.resetSelectedMethod(e), m; | ||
} catch (h) { | ||
throw yield this.resetSelectedMethod(e), h; | ||
} | ||
d.onvalidatemerchant = (m) => { | ||
fetch(`${Z()}/api/v1/providers/applepay/session/`, { | ||
d.onvalidatemerchant = (h) => { | ||
fetch(`${te()}/api/v1/providers/applepay/session/`, { | ||
method: "post", | ||
@@ -453,3 +453,3 @@ headers: { | ||
secret: p.secret, | ||
validation_url: m.validationURL | ||
validation_url: h.validationURL | ||
}) | ||
@@ -459,4 +459,4 @@ }).then((g) => g.ok ? g.json() : Promise.reject()).then( | ||
).catch(c); | ||
}, d.onpaymentauthorized = (m) => { | ||
fetch(`${Z()}/api/v1/providers/applepay/token/`, { | ||
}, d.onpaymentauthorized = (h) => { | ||
fetch(`${te()}/api/v1/providers/applepay/token/`, { | ||
method: "post", | ||
@@ -467,3 +467,3 @@ headers: { | ||
body: JSON.stringify({ | ||
token_data: m.payment.token, | ||
token_data: h.payment.token, | ||
secret: p.secret | ||
@@ -496,3 +496,3 @@ }) | ||
renderForm({ 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 }); | ||
return E(!e, "selector is required for renderForm"), E(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t }); | ||
} | ||
@@ -512,3 +512,3 @@ /** | ||
setLocale(e) { | ||
Q( | ||
Z( | ||
!!e && !q.has(e), | ||
@@ -548,3 +548,3 @@ `Invalid locale. Supported languages (${[...q].join( | ||
}) { | ||
return P(!t.title.en, "English discount title is required!"), this.sdkApiHandler.request({ | ||
return E(!t.title.en, "English discount title is required!"), this.sdkApiHandler.request({ | ||
api: "sdk:updateIntentDiscount", | ||
@@ -575,3 +575,3 @@ payload: { | ||
return t.forEach((o) => { | ||
P(!o.title.en, "English fee title is required!"); | ||
E(!o.title.en, "English fee title is required!"); | ||
}), this.sdkApiHandler.request({ | ||
@@ -601,3 +601,3 @@ api: "sdk:updateIntentFees", | ||
let i = !1; | ||
return y(this, M, ie).call(this, r), { | ||
return P(this, $, oe).call(this, r), { | ||
/** | ||
@@ -628,5 +628,5 @@ * Creates card field element | ||
let u = null, p; | ||
const m = k(k({}, t), l.classes), g = ((W = m == null ? void 0 : m.focus) == null ? void 0 : W.split(" ")) || [ | ||
const h = k(k({}, t), l.classes), g = ((W = h == null ? void 0 : h.focus) == null ? void 0 : W.split(" ")) || [ | ||
"MoneyHashElement--focus" | ||
], D = ((j = m == null ? void 0 : m.error) == null ? void 0 : j.split(" ")) || [ | ||
], D = ((j = h == null ? void 0 : h.error) == null ? void 0 : j.split(" ")) || [ | ||
"MoneyHashElement--error" | ||
@@ -638,21 +638,21 @@ ]; | ||
l.selector | ||
), P( | ||
), E( | ||
!p, | ||
`Couldn't find an element with selector ${l.selector}!` | ||
), p.classList.add("MoneyHashElement"), r.push((h) => { | ||
var x, T, B, Y, O, z, J; | ||
const { type: E, data: S } = h.data; | ||
if (E === `${a}@mount` && (n[a] = S.isValid, (x = d.get(`${a}@mount`)) == null || x()), E === `${a}@focus`) { | ||
p.classList.add(...g), (T = d.get(`${a}@focus`)) == null || T(); | ||
), p.classList.add("MoneyHashElement"), r.push((m) => { | ||
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(); | ||
return; | ||
} | ||
if (E === `${a}@blur`) { | ||
p.classList.remove(...g), (B = d.get(`${a}@blur`)) == null || B(); | ||
if (y === `${a}@blur`) { | ||
p.classList.remove(...g), (T = d.get(`${a}@blur`)) == null || T(); | ||
return; | ||
} | ||
if (E === `${a}@error`) { | ||
if (y === `${a}@error`) { | ||
S.isValid ? p.classList.remove(...D) : p.classList.add(...D), (Y = d.get(`${a}@error`)) == null || Y(S); | ||
return; | ||
} | ||
if (E === `${a}@changeInput`) { | ||
if (y === `${a}@changeInput`) { | ||
if ((O = d.get(`${a}@changeInput`)) == null || O({ | ||
@@ -669,6 +669,14 @@ isValid: S.isValid, | ||
} | ||
E === `${a}@cardNumberChange` && ((J = d.get(`${a}@cardNumberChange`)) == null || J( | ||
S | ||
)); | ||
}), u = y(this, _, oe).call(this, { | ||
if (y === `${a}@cardNumberChange`) { | ||
(J = d.get(`${a}@cardNumberChange`)) == null || J( | ||
S | ||
); | ||
return; | ||
} | ||
if (y === `${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, _, ce).call(this, { | ||
container: p, | ||
@@ -681,9 +689,9 @@ elementType: a, | ||
}, | ||
on: (h, E) => { | ||
d.set(`${a}@${h}`, E); | ||
on: (m, y) => { | ||
d.set(`${a}@${m}`, y); | ||
}, | ||
off: (h) => d.delete(`${a}@${h}`), | ||
off: (m) => d.delete(`${a}@${m}`), | ||
focus: () => { | ||
var h; | ||
(h = u == null ? void 0 : u.contentWindow) == null || h.postMessage( | ||
var m; | ||
(m = u == null ? void 0 : u.contentWindow) == null || m.postMessage( | ||
{ type: "focus" }, | ||
@@ -694,4 +702,4 @@ A() | ||
blur: () => { | ||
var h; | ||
(h = u == null ? void 0 : u.contentWindow) == null || h.postMessage( | ||
var m; | ||
(m = u == null ? void 0 : u.contentWindow) == null || m.postMessage( | ||
{ type: "blur" }, | ||
@@ -702,4 +710,4 @@ A() | ||
clear: () => { | ||
var h; | ||
(h = u == null ? void 0 : u.contentWindow) == null || h.postMessage( | ||
var m; | ||
(m = u == null ? void 0 : u.contentWindow) == null || m.postMessage( | ||
{ type: "clear" }, | ||
@@ -738,13 +746,13 @@ A() | ||
}) { | ||
const i = ye(this.mountedCardElements); | ||
P( | ||
const i = Ee(this.mountedCardElements); | ||
E( | ||
!!i, | ||
`You must mount ${i} element!` | ||
); | ||
const a = new X(); | ||
const a = new ee(); | ||
let l, d; | ||
t && (this.vaultSubmitListener.current = (p) => { | ||
const { type: m, data: g } = p.data; | ||
m === "vaultSubmit:success" && a.resolve(g), m === "vaultSubmit:error" && a.reject(g); | ||
}, d = y(this, F, de).call(this, { accessToken: t, saveCard: n }), l = yield a.promise); | ||
const { type: h, data: g } = p.data; | ||
h === "vaultSubmit:success" && a.resolve(g), h === "vaultSubmit:error" && a.reject(g); | ||
}, d = P(this, F, le).call(this, { accessToken: t, saveCard: n }), l = yield a.promise); | ||
const u = yield this.sdkApiHandler.request({ | ||
@@ -807,7 +815,7 @@ api: "sdk:submitNativeForm", | ||
case "IFRAME": | ||
return y(this, C, re).call(this, { url: t, intentId: e }); | ||
return P(this, C, ne).call(this, { url: t, intentId: e }); | ||
case "POPUP_IFRAME": | ||
return y(this, U, ae).call(this, { url: t, intentId: e, options: r }); | ||
return P(this, U, ie).call(this, { url: t, intentId: e, options: r }); | ||
case "REDIRECT": | ||
return y(this, R, ne).call(this, { url: t, options: r }); | ||
return P(this, R, se).call(this, { url: t, options: r }); | ||
default: | ||
@@ -831,3 +839,3 @@ return null; | ||
if (!e) | ||
return Q( | ||
return Z( | ||
!0, | ||
@@ -850,3 +858,3 @@ `No expiration date provided!, make sure to check for it before usage | ||
} | ||
C = new WeakSet(), re = function(o) { | ||
C = new WeakSet(), ne = function(o) { | ||
return f(this, arguments, function* ({ | ||
@@ -857,3 +865,3 @@ intentId: e, | ||
const r = document.querySelector("#rendered-url-iframe-container"); | ||
P( | ||
E( | ||
!r, | ||
@@ -863,5 +871,5 @@ "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 y(this, I, H).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 P(this, I, H).call(this, { intentId: e }), n.remove(); | ||
}); | ||
}, U = new WeakSet(), ae = function(r) { | ||
}, U = new WeakSet(), ie = function(r) { | ||
return f(this, arguments, function* ({ | ||
@@ -882,5 +890,5 @@ intentId: e, | ||
); | ||
P(!l, "Popup blocked by browser!"), yield y(this, I, H).call(this, { intentId: e, isUsingPopUp: !0 }), l == null || l.close(); | ||
E(!l, "Popup blocked by browser!"), yield P(this, I, H).call(this, { intentId: e, isUsingPopUp: !0 }), l == null || l.close(); | ||
}); | ||
}, R = new WeakSet(), ne = function(o) { | ||
}, R = new WeakSet(), se = function(o) { | ||
return f(this, arguments, function* ({ | ||
@@ -901,5 +909,5 @@ url: e, | ||
}) { | ||
const r = new X(), n = (c) => f(this, null, function* () { | ||
const r = new ee(), n = (c) => f(this, null, function* () { | ||
var a, l, d, u; | ||
if (c.origin !== te()) | ||
if (c.origin !== ae()) | ||
return; | ||
@@ -911,5 +919,5 @@ const { type: i } = c.data; | ||
this.getIntentDetails(e), | ||
Ee(2) | ||
]), m = p.transaction.status.split(".")[1]; | ||
m === "successful" || m.startsWith("pending") ? (l = (a = this.options).onComplete) == null || l.call(a, k({ | ||
Se(2) | ||
]), h = p.transaction.status.split(".")[1]; | ||
h === "successful" || h.startsWith("pending") ? (l = (a = this.options).onComplete) == null || l.call(a, k({ | ||
type: this.options.type | ||
@@ -923,3 +931,3 @@ }, p)) : (u = (d = this.options).onFail) == null || u.call(d, k({ | ||
}); | ||
}, M = new WeakSet(), ie = function(e) { | ||
}, $ = new WeakSet(), oe = function(e) { | ||
const t = (o) => { | ||
@@ -931,3 +939,3 @@ o.origin === A() && e.forEach((r) => { | ||
window.addEventListener("message", t); | ||
}, $ = new WeakSet(), se = function(e) { | ||
}, M = new WeakSet(), de = function(e) { | ||
const t = (o) => { | ||
@@ -937,3 +945,3 @@ e.current && e.current(o); | ||
window.addEventListener("message", t); | ||
}, _ = new WeakSet(), oe = function({ | ||
}, _ = new WeakSet(), ce = function({ | ||
container: e, | ||
@@ -962,7 +970,7 @@ elementType: t, | ||
return a.src = i.toString(), a.style.height = (p = r == null ? void 0 : r.height) != null ? p : "40px", a.style.setProperty("overflow", "hidden", "important"), a.style.setProperty("display", "block", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("maxWidth", "100%", "important"), a.style.setProperty("border", "0", "important"), a.style.setProperty("margin", "0", "important"), a.style.setProperty("padding", "0", "important"), a.style.setProperty("userSelect", "none", "important"), a.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(a), a; | ||
}, F = new WeakSet(), de = function({ | ||
}, F = new WeakSet(), le = function({ | ||
accessToken: e, | ||
saveCard: t | ||
}) { | ||
const o = A(), r = we(), n = new URL( | ||
const o = A(), r = Pe(), n = new URL( | ||
`${o}/vaultSubmit/vaultSubmit.html` | ||
@@ -975,3 +983,3 @@ ); | ||
export { | ||
Le as default | ||
Ce as default | ||
}; |
@@ -1,2 +0,2 @@ | ||
(function(l,o){typeof exports=="object"&&typeof module!="undefined"?module.exports=o():typeof define=="function"&&define.amd?define(o):(l=typeof globalThis!="undefined"?globalThis:l||self,l.MoneyHash=o())})(this,function(){var q,oe,j,de,D,ce,F,z,W,le,x,he,T,me,O,ue;"use strict";var we=Object.defineProperty,be=Object.defineProperties;var Ee=Object.getOwnPropertyDescriptors;var re=Object.getOwnPropertySymbols;var Pe=Object.prototype.hasOwnProperty,Se=Object.prototype.propertyIsEnumerable;var Y=(l,o,p)=>o in l?we(l,o,{enumerable:!0,configurable:!0,writable:!0,value:p}):l[o]=p,k=(l,o)=>{for(var p in o||(o={}))Pe.call(o,p)&&Y(l,p,o[p]);if(re)for(var p of re(o))Se.call(o,p)&&Y(l,p,o[p]);return l},ae=(l,o)=>be(l,Ee(o));var y=(l,o,p)=>(Y(l,typeof o!="symbol"?o+"":o,p),p),ke=(l,o,p)=>{if(!o.has(l))throw TypeError("Cannot "+p)};var A=(l,o,p)=>{if(o.has(l))throw TypeError("Cannot add the same private member more than once");o instanceof WeakSet?o.add(l):o.set(l,p)};var L=(l,o,p)=>(ke(l,o,"access private method"),p);var E=(l,o,p)=>new Promise((I,w)=>{var V=S=>{try{$(p.next(S))}catch(_){w(_)}},M=S=>{try{$(p.throw(S))}catch(_){w(_)}},$=S=>S.done?I(S.value):Promise.resolve(S.value).then(V,M);$((p=p.apply(l,o)).next())});class l{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 o(){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=o(),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.0");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),P.messagingService=new l({target:r.contentWindow,targetOrigin:e}),P.isCommunicationReady=new Promise(i=>{var h;const s=a=>{var n;a.data.type==="headlessSDK:init"&&(i(),(n=P.messagingService)==null||n.removeListener(s))};(h=P.messagingService)==null||h.onReceive(s)})}request(r){return E(this,arguments,function*({api:e,payload:t}){return yield P.isCommunicationReady,new Promise((i,s)=>{var a,n;(a=P.messagingService)==null||a.send({type:e,data:t});const h=u=>{var m;const{type:d,data:c}=u.data;d===e&&(c.status==="resolved"?i(c.payload):s(c.payload),(m=P.messagingService)==null||m.removeListener(h))};(n=P.messagingService)==null||n.onReceive(h)})})}postMessage(e){var t;(t=P.messagingService)==null||t.send({type:e})}};let I=P;y(I,"messagingService",null),y(I,"isCommunicationReady");function w(f,e){if(f)throw new Error(e)}const V=new Set(["payment","payout"]),M=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 a,n;(a=this.messagingService)==null||a.abortService();const r=o(),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.0");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 h=document.querySelector(e);return w(!h,`Couldn't find an element with selector ${e}!`),h.replaceChildren(this.iframe),this.messagingService=new l({target:this.iframe.contentWindow,targetOrigin:r}),this.isCommunicationReady=new Promise(u=>{var c;const d=m=>{var g;m.data.type==="sdk:init"&&(u(),(g=this.messagingService)==null||g.removeListener(d))};(c=this.messagingService)==null||c.onReceive(d)}),this.messagingService.onReceive((u,d)=>{var g,v,H,N;const{type:c,data:m}=u.data;switch(c){case"sdk:init":{d({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,k({type:this.options.type},m)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(N=(H=this.options).onFail)==null||N.call(H,k({type:this.options.type},m)),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 S{constructor(){y(this,"promise");y(this,"resolve");y(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function _(){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 J(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function pe(f){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!f.includes(t))return t;return null}function ge(f){return(Array.isArray(f)?f.length:Object.keys(f).length)===0}function fe(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 ye(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 ve{constructor(e){A(this,q);A(this,j);A(this,D);A(this,F);A(this,W);A(this,x);A(this,T);A(this,O);y(this,"options");y(this,"sdkApiHandler",new I);y(this,"sdkEmbed");y(this,"vaultSubmitListener",{current:null});y(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new $(ae(k({},e),{headless:!0})),L(this,x,he).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:h,onComplete:a,billingData:n={}}){if(yield fe("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const d=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:c,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(c==="INTENT_FORM"){if(ge(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(`${J()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:g.validationURL})}).then(v=>v.ok?v.json():Promise.reject()).then(v=>d.completeMerchantValidation(v)).catch(h)},d.onpaymentauthorized=g=>{fetch(`${J()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:g.payment.token,secret:m.secret})}).then(v=>v.ok?v.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{d.completePayment(ApplePaySession.STATUS_FAILURE),h()})},d.oncancel=s,d.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&&!M.has(e),`Invalid locale. Supported languages (${[...M].join(" | ")})`);const t=M.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={},h=new Map;let a=!1;return L(this,W,le).call(this,i),{create:({elementType:n,elementOptions:u})=>{var N,Q;const d=new Map;let c=null,m;const g=k(k({},t),u.classes),v=((N=g==null?void 0:g.focus)==null?void 0:N.split(" "))||["MoneyHashElement--focus"],H=((Q=g==null?void 0:g.error)==null?void 0:Q.split(" "))||["MoneyHashElement--error"];return{mount:()=>{m=document.querySelector(u.selector),w(!m,`Couldn't find an element with selector ${u.selector}!`),m.classList.add("MoneyHashElement"),i.push(b=>{var X,Z,ee,te,ie,ne,se;const{type:R,data:C}=b.data;if(R===`${n}@mount`&&(s[n]=C.isValid,(X=d.get(`${n}@mount`))==null||X()),R===`${n}@focus`){m.classList.add(...v),(Z=d.get(`${n}@focus`))==null||Z();return}if(R===`${n}@blur`){m.classList.remove(...v),(ee=d.get(`${n}@blur`))==null||ee();return}if(R===`${n}@error`){C.isValid?m.classList.remove(...H):m.classList.add(...H),(te=d.get(`${n}@error`))==null||te(C);return}if(R===`${n}@changeInput`){if((ie=d.get(`${n}@changeInput`))==null||ie({isValid:C.isValid,length:C.length}),s[n]=C.isValid,h.get("validityChange")){const B=Object.values(s).every(Boolean);B!==a&&((ne=h.get("validityChange"))==null||ne(B),a=B)}return}R===`${n}@cardNumberChange`&&((se=d.get(`${n}@cardNumberChange`))==null||se(C))}),c=L(this,T,me).call(this,{container:m,elementType:n,elementOptions:u,styles:k(k({},e),u.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(b,R)=>{d.set(`${n}@${b}`,R)},off:b=>d.delete(`${n}@${b}`),focus:()=>{var b;(b=c==null?void 0:c.contentWindow)==null||b.postMessage({type:"focus"},U())},blur:()=>{var b;(b=c==null?void 0:c.contentWindow)==null||b.postMessage({type:"blur"},U())},clear:()=>{var b;(b=c==null?void 0:c.contentWindow)==null||b.postMessage({type:"clear"},U())}}},on:(n,u)=>{h.set(n,u)}}}submitForm(h){return E(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:i,saveCard:s}){const a=pe(this.mountedCardElements);w(!!a,`You must mount ${a} element!`);const n=new S;let u,d;t&&(this.vaultSubmitListener.current=m=>{const{type:g,data:v}=m.data;g==="vaultSubmit:success"&&n.resolve(v),g==="vaultSubmit:error"&&n.reject(v)},d=L(this,O,ue).call(this,{accessToken:t,saveCard:s}),u=yield n.promise);const c=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:i,cardEmbed:u}});return d&&d.remove(),c})}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,oe).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return L(this,j,de).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return L(this,D,ce).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(l,o){typeof exports=="object"&&typeof module!="undefined"?module.exports=o():typeof define=="function"&&define.amd?define(o):(l=typeof globalThis!="undefined"?globalThis:l||self,l.MoneyHash=o())})(this,function(){var q,ce,j,le,D,he,F,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=(l,o,p)=>o in l?Ee(l,o,{enumerable:!0,configurable:!0,writable:!0,value:p}):l[o]=p,L=(l,o)=>{for(var p in o||(o={}))Se.call(o,p)&&Y(l,p,o[p]);if(oe)for(var p of oe(o))Le.call(o,p)&&Y(l,p,o[p]);return l},de=(l,o)=>Pe(l,ke(o));var y=(l,o,p)=>(Y(l,typeof o!="symbol"?o+"":o,p),p),Ae=(l,o,p)=>{if(!o.has(l))throw TypeError("Cannot "+p)};var R=(l,o,p)=>{if(o.has(l))throw TypeError("Cannot add the same private member more than once");o instanceof WeakSet?o.add(l):o.set(l,p)};var A=(l,o,p)=>(Ae(l,o,"access private method"),p);var E=(l,o,p)=>new Promise((I,w)=>{var V=k=>{try{$(p.next(k))}catch(_){w(_)}},M=k=>{try{$(p.throw(k))}catch(_){w(_)}},$=k=>k.done?I(k.value):Promise.resolve(k.value).then(V,M);$((p=p.apply(l,o)).next())});class l{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 o(){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=o(),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.1");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),P.messagingService=new l({target:r.contentWindow,targetOrigin:e}),P.isCommunicationReady=new Promise(i=>{var h;const s=a=>{var n;a.data.type==="headlessSDK:init"&&(i(),(n=P.messagingService)==null||n.removeListener(s))};(h=P.messagingService)==null||h.onReceive(s)})}request(r){return E(this,arguments,function*({api:e,payload:t}){return yield P.isCommunicationReady,new Promise((i,s)=>{var a,n;(a=P.messagingService)==null||a.send({type:e,data:t});const h=u=>{var m;const{type:d,data:c}=u.data;d===e&&(c.status==="resolved"?i(c.payload):s(c.payload),(m=P.messagingService)==null||m.removeListener(h))};(n=P.messagingService)==null||n.onReceive(h)})})}postMessage(e){var t;(t=P.messagingService)==null||t.send({type:e})}};let I=P;y(I,"messagingService",null),y(I,"isCommunicationReady");function w(f,e){if(f)throw new Error(e)}const V=new Set(["payment","payout"]),M=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 a,n;(a=this.messagingService)==null||a.abortService();const r=o(),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.1");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 h=document.querySelector(e);return w(!h,`Couldn't find an element with selector ${e}!`),h.replaceChildren(this.iframe),this.messagingService=new l({target:this.iframe.contentWindow,targetOrigin:r}),this.isCommunicationReady=new Promise(u=>{var c;const d=m=>{var g;m.data.type==="sdk:init"&&(u(),(g=this.messagingService)==null||g.removeListener(d))};(c=this.messagingService)==null||c.onReceive(d)}),this.messagingService.onReceive((u,d)=>{var g,v,H,N;const{type:c,data:m}=u.data;switch(c){case"sdk:init":{d({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},m)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(N=(H=this.options).onFail)==null||N.call(H,L({type:this.options.type},m)),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 _(){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 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,F);R(this,W);R(this,x);R(this,B);R(this,O);y(this,"options");y(this,"sdkApiHandler",new I);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:h,onComplete:a,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:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:c,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(c==="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}d.onvalidatemerchant=g=>{fetch(`${J()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:g.validationURL})}).then(v=>v.ok?v.json():Promise.reject()).then(v=>d.completeMerchantValidation(v)).catch(h)},d.onpaymentauthorized=g=>{fetch(`${J()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:g.payment.token,secret:m.secret})}).then(v=>v.ok?v.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{d.completePayment(ApplePaySession.STATUS_FAILURE),h()})},d.oncancel=s,d.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&&!M.has(e),`Invalid locale. Supported languages (${[...M].join(" | ")})`);const t=M.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={},h=new Map;let a=!1;return A(this,W,me).call(this,i),{create:({elementType:n,elementOptions:u})=>{var N,Q;const d=new Map;let c=null,m;const g=L(L({},t),u.classes),v=((N=g==null?void 0:g.focus)==null?void 0:N.split(" "))||["MoneyHashElement--focus"],H=((Q=g==null?void 0:g.error)==null?void 0:Q.split(" "))||["MoneyHashElement--error"];return{mount:()=>{m=document.querySelector(u.selector),w(!m,`Couldn't find an element with selector ${u.selector}!`),m.classList.add("MoneyHashElement"),i.push(b=>{var X,Z,ee,te,ie,ne,se,re,ae;const{type:S,data:C}=b.data;if(S===`${n}@mount`&&(s[n]=C.isValid,(X=d.get(`${n}@mount`))==null||X()),S===`${n}@focus`){m.classList.add(...v),(Z=d.get(`${n}@focus`))==null||Z();return}if(S===`${n}@blur`){m.classList.remove(...v),(ee=d.get(`${n}@blur`))==null||ee();return}if(S===`${n}@error`){C.isValid?m.classList.remove(...H):m.classList.add(...H),(te=d.get(`${n}@error`))==null||te(C);return}if(S===`${n}@changeInput`){if((ie=d.get(`${n}@changeInput`))==null||ie({isValid:C.isValid,length:C.length}),s[n]=C.isValid,h.get("validityChange")){const T=Object.values(s).every(Boolean);T!==a&&((ne=h.get("validityChange"))==null||ne(T),a=T)}return}if(S===`${n}@cardNumberChange`){(se=d.get(`${n}@cardNumberChange`))==null||se(C);return}if(S===`${n}@key:Backspace`){(re=d.get(`${n}@key:Backspace`))==null||re();return}S===`${n}@key:Enter`&&((ae=d.get(`${n}@key:Enter`))==null||ae())}),c=A(this,B,pe).call(this,{container:m,elementType:n,elementOptions:u,styles:L(L({},e),u.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(b,S)=>{d.set(`${n}@${b}`,S)},off:b=>d.delete(`${n}@${b}`),focus:()=>{var b;(b=c==null?void 0:c.contentWindow)==null||b.postMessage({type:"focus"},U())},blur:()=>{var b;(b=c==null?void 0:c.contentWindow)==null||b.postMessage({type:"blur"},U())},clear:()=>{var b;(b=c==null?void 0:c.contentWindow)==null||b.postMessage({type:"clear"},U())}}},on:(n,u)=>{h.set(n,u)}}}submitForm(h){return E(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:i,saveCard:s}){const a=fe(this.mountedCardElements);w(!!a,`You must mount ${a} element!`);const n=new k;let u,d;t&&(this.vaultSubmitListener.current=m=>{const{type:g,data:v}=m.data;g==="vaultSubmit:success"&&n.resolve(v),g==="vaultSubmit:error"&&n.reject(v)},d=A(this,O,ge).call(this,{accessToken:t,saveCard:s}),u=yield n.promise);const c=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:i,cardEmbed:u}});return d&&d.remove(),c})}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 | ||
@@ -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,oe=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 L(this,F,z).call(this,{intentId:e}),s.remove()})},j=new WeakSet,de=function(i){return E(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:h=400,left:a=200,top:n=200}=r.window||{},u=window.open(t,"",`width=${s},height=${h},left=${a},top=${n}`);w(!u,"Popup blocked by browser!"),yield L(this,F,z).call(this,{intentId:e,isUsingPopUp:!0}),u==null||u.close()})},D=new WeakSet,ce=function(r){return E(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},F=new WeakSet,z=function(r){return E(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new S,s=h=>E(this,null,function*(){var n,u,d,c;if(h.origin!==o())return;const{type:a}=h.data;if(a==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),ye(2)]),g=m.transaction.status.split(".")[1];g==="successful"||g.startsWith("pending")?(u=(n=this.options).onComplete)==null||u.call(n,k({type:this.options.type},m)):(c=(d=this.options).onFail)==null||c.call(d,k({type:this.options.type},m)),i.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),i.promise})},W=new WeakSet,le=function(e){const t=r=>{r.origin===U()&&e.forEach(i=>{i(r)})};window.addEventListener("message",t)},x=new WeakSet,he=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},T=new WeakSet,me=function({container:e,elementType:t,elementOptions:r,styles:i,fontSourceCss:s}){var u,d,c,m;const h=U(),a=new URL(`${h}/vaultField/vaultField.html`);s&&a.searchParams.set("fontSourceCss",s),a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("type",t),((u=r.validation)==null?void 0:u.required)!==void 0&&a.searchParams.set("required",`${(d=r.validation)==null?void 0:d.required}`),a.searchParams.set("placeholder",(c=r.placeholder)!=null?c:""),a.searchParams.set("lang",this.sdkEmbed.lang),a.searchParams.set("direction",(i==null?void 0:i.direction)||""),a.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),a.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),a.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),a.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),a.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),a.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),a.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),a.searchParams.set("padding",(i==null?void 0:i.padding)||"");const n=document.createElement("iframe");return n.src=a.toString(),n.style.height=(m=i==null?void 0:i.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},O=new WeakSet,ue=function({accessToken:e,saveCard:t}){const r=U(),i=_(),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 h=document.createElement("iframe");return h.id="moneyhash-submit-iframe",h.src=s.toString(),h.hidden=!0,document.body.appendChild(h),h},ve}); | ||
}`),()=>{};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,F,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:h=400,left:a=200,top:n=200}=r.window||{},u=window.open(t,"",`width=${s},height=${h},left=${a},top=${n}`);w(!u,"Popup blocked by browser!"),yield A(this,F,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")})},F=new WeakSet,z=function(r){return E(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new k,s=h=>E(this,null,function*(){var n,u,d,c;if(h.origin!==o())return;const{type:a}=h.data;if(a==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),we(2)]),g=m.transaction.status.split(".")[1];g==="successful"||g.startsWith("pending")?(u=(n=this.options).onComplete)==null||u.call(n,L({type:this.options.type},m)):(c=(d=this.options).onFail)==null||c.call(d,L({type:this.options.type},m)),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===U()&&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,d,c,m;const h=U(),a=new URL(`${h}/vaultField/vaultField.html`);s&&a.searchParams.set("fontSourceCss",s),a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("type",t),((u=r.validation)==null?void 0:u.required)!==void 0&&a.searchParams.set("required",`${(d=r.validation)==null?void 0:d.required}`),a.searchParams.set("placeholder",(c=r.placeholder)!=null?c:""),a.searchParams.set("lang",this.sdkEmbed.lang),a.searchParams.set("direction",(i==null?void 0:i.direction)||""),a.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),a.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),a.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),a.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),a.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),a.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),a.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),a.searchParams.set("padding",(i==null?void 0:i.padding)||"");const n=document.createElement("iframe");return n.src=a.toString(),n.style.height=(m=i==null?void 0:i.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},O=new WeakSet,ge=function({accessToken:e,saveCard:t}){const r=U(),i=_(),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 h=document.createElement("iframe");return h.id="moneyhash-submit-iframe",h.src=s.toString(),h.hidden=!0,document.body.appendChild(h),h},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-fba58e46.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-604ca43b.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; |
@@ -85,3 +85,3 @@ export declare interface AbstractIntent { | ||
}) => void): void; | ||
on<T extends Extract<ElementEvents, "mount" | "focus" | "blur">>(event: T, callback: () => void): void; | ||
on<T extends ElementEvents>(event: T, callback: () => void): void; | ||
off: (event: ElementEvents) => boolean; | ||
@@ -96,3 +96,3 @@ focus: () => void; | ||
export declare type ElementEvents = "mount" | "focus" | "blur" | "error" | "changeInput" | "cardNumberChange"; | ||
export declare type ElementEvents = "mount" | "focus" | "blur" | "error" | "changeInput" | "cardNumberChange" | "key:Backspace" | "key:Enter"; | ||
@@ -99,0 +99,0 @@ export declare type ElementProps = { |
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-daa85568.js"; | ||
import { S as i, t as d, w as u, s as a } from "./warnIf-f9a95079.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.0");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-beta.1");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.0", | ||
"version": "1.5.2-beta.1", | ||
"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
380412
2577